# Set working directory

setwd("")

# Load required packages

library(foreign)
library(Hmisc)
library(mediation)
library(lme4)
library(lmerTest)
library(multcomp)
library(lsmeans)
library(gridExtra)
library(texreg)
library(effects)
library(boot)
library(arm)
library(xtable)
library(car)
library(merTools)
library(plotrix)
library(nloptr)
library(pastecs)
library(psych)
library(haven)

scale.01 <- function(x){
  (x-min(x, na.rm =T))/(max(x, na.rm =T)-min(x, na.rm =T))}

## Load main data file
csscohort <- read_dta("csscohort_final.dta") 

## Create subsets for low, middle, and high income students

data.lis <- csscohort[csscohort$parinc == "Low-Income",]
data.mis <- csscohort[csscohort$parinc == "Middle-Income",]
data.his <- csscohort[csscohort$parinc == "High-Income",]

##########################################################################################
############################ MAIN PAPER ##################################################
##########################################################################################
##########################################################################################

# Calculate the number of students and schools in the analytical sample

nrow(data.lis) #17,462 
nrow(data.mis) #114,580 
nrow(data.his) #120,684 
length(unique(csscohort$ACERECODE)) #647
length(unique(csscohort$ace_year)) #3,260

############
# Figure 1 #
############

# Note that p-values and coefficients may vary slightly each time the models are run
# Results were originally created using R version 3.6.2 and lme4 version 1.1-21. 


#########################
# Passive participation #
#########################

set.seed(12345)

passive.lis <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                      evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                      hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                      age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                      largesb + public + college + neast + south + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), data = data.lis)  

passive.lis

passive.mis <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                      evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                      hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                      age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                      largesb + public + college + neast + south + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), data = data.mis)  

passive.mis

passive.his <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                      evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                      hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                      age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                      largesb + public + college + neast + south + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), data = data.his)  

passive.his

modelvars <- c("passive_index_css_avg", "passive_index_tfs_avg", "affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black", "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs", "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south", "YEAR", "ACERECODE", "ace_year")

csscohort2 <- csscohort[complete.cases(csscohort[,modelvars]),]

data.lis.temp <- csscohort2[csscohort2$parinc == "Low-Income",]
data.mis.temp  <- csscohort2[csscohort2$parinc == "Middle-Income",]
data.his.temp  <- csscohort2[csscohort2$parinc == "High-Income",]

passive.lis.p <- summary(passive.lis)$coefficients["factor(affcat)5",5] 

data.lis.temp$affcat <- 1
passive.lis.lis.1 <- mean(predict(passive.lis, data.lis.temp, re.form=NULL)) 
data.lis.temp$affcat <- 5
passive.lis.lis.5 <- mean(predict(passive.lis, data.lis.temp, re.form=NULL)) 
passive.lis.eff <- passive.lis.lis.5 - passive.lis.lis.1

passive.mis.p <- summary(passive.mis)$coefficients["factor(affcat)5",5] 

data.mis.temp$affcat <- 1
passive.mis.lis.1 <- mean(predict(passive.mis, data.mis.temp, re.form=NULL)) 
data.mis.temp$affcat <- 5
passive.mis.lis.5 <- mean(predict(passive.mis, data.mis.temp, re.form=NULL)) 
passive.mis.eff <- passive.mis.lis.5 - passive.mis.lis.1

passive.his.p <- summary(passive.his)$coefficients["factor(affcat)5",5] 

data.his.temp$affcat <- 1
passive.his.lis.1 <- mean(predict(passive.his, data.his.temp, re.form=NULL)) 
data.his.temp$affcat <- 5
passive.his.lis.5 <- mean(predict(passive.his, data.his.temp, re.form=NULL)) 
passive.his.eff <- passive.his.lis.5 - passive.his.lis.1

passive.re.lis.full.coefs <- data.frame(coef(summary(passive.lis)))
passive.re.lis.full.coefs$p.z <- 2 * (1 - pnorm(abs(passive.re.lis.full.coefs$t.value)))

passive.re.mis.full.coefs <- data.frame(coef(summary(passive.mis)))
passive.re.mis.full.coefs$p.z <- 2 * (1 - pnorm(abs(passive.re.mis.full.coefs$t.value)))

passive.re.his.full.coefs <- data.frame(coef(summary(passive.his)))
passive.re.his.full.coefs$p.z <- 2 * (1 - pnorm(abs(passive.re.his.full.coefs$t.value)))

##########
# Voting #
##########

set.seed(12345)

voteprez2.lis <- glmer(voteprez2 ~ polaffairs_tfs + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                        otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                        hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                        socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                        factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

voteprez2.lis

voteprez2.mis <- glmer(voteprez2 ~ polaffairs_tfs + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                        otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                        hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                        socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                        factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.mis)

voteprez2.mis

voteprez2.his <- glmer(voteprez2 ~ polaffairs_tfs + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                        otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                        hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                        socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                        factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.his)

voteprez2.his

modelvars <- c("voteprez2", "polaffairs_tfs", "affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black", "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs", "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south", "YEAR", "ACERECODE", "ace_year")

csscohort2 <- csscohort[complete.cases(csscohort[,modelvars]),]

data.lis.temp <- csscohort2[csscohort2$parinc == "Low-Income",]
data.mis.temp  <- csscohort2[csscohort2$parinc == "Middle-Income",]
data.his.temp  <- csscohort2[csscohort2$parinc == "High-Income",]

voteprez2.lis.p <- summary(voteprez2.lis)$coefficients["factor(affcat)5",4] 

data.lis.temp$affcat <- 1
voteprez2.lis.lis.1 <- mean(predict(voteprez2.lis, data.lis.temp, re.form=NULL, type = "response")) 
data.lis.temp$affcat <- 5
voteprez2.lis.lis.5 <- mean(predict(voteprez2.lis, data.lis.temp, re.form=NULL, type = "response")) 
voteprez2.lis.eff <- voteprez2.lis.lis.5 - voteprez2.lis.lis.1

voteprez2.mis.p <- summary(voteprez2.mis)$coefficients["factor(affcat)5",4] 

data.mis.temp$affcat <- 1
voteprez2.mis.lis.1 <- mean(predict(voteprez2.mis, data.mis.temp, re.form=NULL, type = "response")) 
data.mis.temp$affcat <- 5
voteprez2.mis.lis.5 <- mean(predict(voteprez2.mis, data.mis.temp, re.form=NULL, type = "response")) 
voteprez2.mis.eff <- voteprez2.mis.lis.5 - voteprez2.mis.lis.1

voteprez2.his.p <- summary(voteprez2.his)$coefficients["factor(affcat)5",4] 

data.his.temp$affcat <- 1
voteprez2.his.lis.1 <- mean(predict(voteprez2.his, data.his.temp, re.form=NULL, type = "response")) 
data.his.temp$affcat <- 5
voteprez2.his.lis.5 <- mean(predict(voteprez2.his, data.his.temp, re.form=NULL, type = "response")) 
voteprez2.his.eff <- voteprez2.his.lis.5 - voteprez2.his.lis.1

###############
# Campaigning #
###############

set.seed(12345)

campaign.lis <- glmer(campaign_css ~ campaign_tfs + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                        otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                        hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                        socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                        factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

campaign.lis

campaign.mis <- glmer(campaign_css ~ campaign_tfs + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                        otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                        hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                        socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                        factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.mis)

campaign.mis 

campaign.his <- glmer(campaign_css ~ campaign_tfs + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                        otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                        hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                        socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                        factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.his)

campaign.his

modelvars <- c("campaign_css", "campaign_tfs", "affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black", "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs", "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south", "YEAR", "ACERECODE", "ace_year")

csscohort2 <- csscohort[complete.cases(csscohort[,modelvars]),]

data.lis.temp <- csscohort2[csscohort2$parinc == "Low-Income",]
data.mis.temp  <- csscohort2[csscohort2$parinc == "Middle-Income",]
data.his.temp  <- csscohort2[csscohort2$parinc == "High-Income",]

campaign.lis.p <- summary(campaign.lis)$coefficients["factor(affcat)5",4] 

data.lis.temp$affcat <- 1
campaign.lis.lis.1 <- mean(predict(campaign.lis, data.lis.temp, re.form=NULL, type = "response")) 
data.lis.temp$affcat <- 5
campaign.lis.lis.5 <- mean(predict(campaign.lis, data.lis.temp, re.form=NULL, type = "response")) 
campaign.lis.eff <- campaign.lis.lis.5 - campaign.lis.lis.1

campaign.mis.p <- summary(campaign.mis)$coefficients["factor(affcat)5",4] 

data.mis.temp$affcat <- 1
campaign.mis.lis.1 <- mean(predict(campaign.mis, data.mis.temp, re.form=NULL, type = "response")) 
data.mis.temp$affcat <- 5
campaign.mis.lis.5 <- mean(predict(campaign.mis, data.mis.temp, re.form=NULL, type = "response")) 
campaign.mis.eff <- campaign.mis.lis.5 - campaign.mis.lis.1

campaign.his.p <- summary(campaign.his)$coefficients["factor(affcat)5",4] 

data.his.temp$affcat <- 1
campaign.his.lis.1 <- mean(predict(campaign.his, data.his.temp, re.form=NULL, type = "response")) 
data.his.temp$affcat <- 5
campaign.his.lis.5 <- mean(predict(campaign.his, data.his.temp, re.form=NULL, type = "response")) 
campaign.his.eff <- campaign.his.lis.5 - campaign.his.lis.1

#############################
# Elected to Student Office #
#############################

set.seed(12345)

elected.lis <- glmer(elected01_gov ~ commlead_tfs + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                       otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                       hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                       socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                       factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)
                       
elected.lis                      

elected.mis <- glmer(elected01_gov ~ commlead_tfs + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                       otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                       hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                       socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                       factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.mis)

elected.mis

elected.his <- glmer(elected01_gov ~ commlead_tfs + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                       otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                       hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                       socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                       factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.his)
elected.his

modelvars <- c("elected01_gov", "commlead_tfs", "affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black", "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs", "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south", "YEAR", "ACERECODE", "ace_year")

csscohort2 <- csscohort[complete.cases(csscohort[,modelvars]),]

data.lis.temp <- csscohort2[csscohort2$parinc == "Low-Income",]
data.mis.temp  <- csscohort2[csscohort2$parinc == "Middle-Income",]
data.his.temp  <- csscohort2[csscohort2$parinc == "High-Income",]

elected.lis.p <- summary(elected.lis)$coefficients["factor(affcat)5",4] 

data.lis.temp$affcat <- 1
elected.lis.lis.1 <- mean(predict(elected.lis, data.lis.temp, re.form=NULL, type = "response")) 
data.lis.temp$affcat <- 5
elected.lis.lis.5 <- mean(predict(elected.lis, data.lis.temp, re.form=NULL, type = "response")) 
elected.lis.eff <- elected.lis.lis.5 - elected.lis.lis.1

elected.mis.p <- summary(elected.mis)$coefficients["factor(affcat)5",4] 

data.mis.temp$affcat <- 1
elected.mis.lis.1 <- mean(predict(elected.mis, data.mis.temp, re.form=NULL, type = "response")) 
data.mis.temp$affcat <- 5
elected.mis.lis.5 <- mean(predict(elected.mis, data.mis.temp, re.form=NULL, type = "response")) 
elected.mis.eff <- elected.mis.lis.5 - elected.mis.lis.1

elected.his.p <- summary(elected.his)$coefficients["factor(affcat)5",4] 

data.his.temp$affcat <- 1
elected.his.lis.1 <- mean(predict(elected.his, data.his.temp, re.form=NULL, type = "response")) 
data.his.temp$affcat <- 5
elected.his.lis.5 <- mean(predict(elected.his, data.his.temp, re.form=NULL, type = "response")) 
elected.his.eff <- elected.his.lis.5 - elected.his.lis.1

##################################
# Leader of Student Organization #
##################################

set.seed(12345)

orglead.lis <- glmer(orglead01 ~ commlead_tfs + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                       otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                       hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                       socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                       factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

orglead.lis                       

orglead.mis <- glmer(orglead01 ~ commlead_tfs + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                       otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                       hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                       socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                       factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.mis)
orglead.mis

orglead.his <- glmer(orglead01 ~ commlead_tfs + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                       otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                       hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                       socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                       factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.his)

orglead.his 

modelvars <- c("orglead01", "commlead_tfs", "affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black", "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs", "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south", "YEAR", "ACERECODE", "ace_year")

csscohort2 <- csscohort[complete.cases(csscohort[,modelvars]),]

data.lis.temp <- csscohort2[csscohort2$parinc == "Low-Income",]
data.mis.temp  <- csscohort2[csscohort2$parinc == "Middle-Income",]
data.his.temp  <- csscohort2[csscohort2$parinc == "High-Income",]

orglead.lis.p <- summary(orglead.lis)$coefficients["factor(affcat)5",4] 

data.lis.temp$affcat <- 1
orglead.lis.lis.1 <- mean(predict(orglead.lis, data.lis.temp, re.form=NULL, type = "response")) 
data.lis.temp$affcat <- 5
orglead.lis.lis.5 <- mean(predict(orglead.lis, data.lis.temp, re.form=NULL, type = "response")) 
orglead.lis.eff <- orglead.lis.lis.5 - orglead.lis.lis.1

orglead.mis.p <- summary(orglead.mis)$coefficients["factor(affcat)5",4] 

data.mis.temp$affcat <- 1
orglead.mis.lis.1 <- mean(predict(orglead.mis, data.mis.temp, re.form=NULL, type = "response")) 
data.mis.temp$affcat <- 5
orglead.mis.lis.5 <- mean(predict(orglead.mis, data.mis.temp, re.form=NULL, type = "response")) 
orglead.mis.eff <- orglead.mis.lis.5 - orglead.mis.lis.1

orglead.his.p <- summary(orglead.his)$coefficients["factor(affcat)5",4] 

data.his.temp$affcat <- 1
orglead.his.lis.1 <- mean(predict(orglead.his, data.his.temp, re.form=NULL, type = "response")) 
data.his.temp$affcat <- 5
orglead.his.lis.5 <- mean(predict(orglead.his, data.his.temp, re.form=NULL, type = "response")) 
orglead.his.eff <- orglead.his.lis.5 - orglead.his.lis.1

#################
# Protest Index #
#################

set.seed(12345)

protest.lis <-  glmer(protestindex_css ~ protest_tfs + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                        otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                        hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                        socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                        factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

protest.lis

protest.mis <- glmer(protestindex_css ~ protest_tfs + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                       otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                       hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                       socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                       factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.mis)

protest.mis

protest.his <- glmer(protestindex_css ~ protest_tfs + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                       otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                       hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                       socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                       factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.his)

protest.his

modelvars <- c("protestindex_css", "protest_tfs", "affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black", "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs", "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south", "YEAR", "ACERECODE", "ace_year")

csscohort2 <- csscohort[complete.cases(csscohort[,modelvars]),]

data.lis.temp <- csscohort2[csscohort2$parinc == "Low-Income",]
data.mis.temp  <- csscohort2[csscohort2$parinc == "Middle-Income",]
data.his.temp  <- csscohort2[csscohort2$parinc == "High-Income",]

protest.lis.p <- summary(protest.lis)$coefficients["factor(affcat)5",4] 

data.lis.temp$affcat <- 1
protest.lis.lis.1 <- mean(predict(protest.lis, data.lis.temp, re.form=NULL, type = "response")) 
data.lis.temp$affcat <- 5
protest.lis.lis.5 <- mean(predict(protest.lis, data.lis.temp, re.form=NULL, type = "response")) 
protest.lis.eff <- protest.lis.lis.5 - protest.lis.lis.1

protest.mis.p <- summary(protest.mis)$coefficients["factor(affcat)5",4] 

data.mis.temp$affcat <- 1
protest.mis.lis.1 <- mean(predict(protest.mis, data.mis.temp, re.form=NULL, type = "response")) 
data.mis.temp$affcat <- 5
protest.mis.lis.5 <- mean(predict(protest.mis, data.mis.temp, re.form=NULL, type = "response")) 
protest.mis.eff <- protest.mis.lis.5 - protest.mis.lis.1

protest.his.p <- summary(protest.his)$coefficients["factor(affcat)5",4] 

data.his.temp$affcat <- 1
protest.his.lis.1 <- mean(predict(protest.his, data.his.temp, re.form=NULL, type = "response")) 
data.his.temp$affcat <- 5
protest.his.lis.5 <- mean(predict(protest.his, data.his.temp, re.form=NULL, type = "response")) 
protest.his.eff <- protest.his.lis.5 - protest.his.lis.1

###################
# Create Figure 1 #
###################

data = data.frame (variable = c("Lead Student Organization", "Lead Student Organization", "Lead Student Organization",
                                "Protest Involvement", "Protest Involvement", "Protest Involvement",
                                "Passive Engagement Index", "Passive Engagement Index", "Passive Engagement Index",
                                "Vote in National Election", "Vote in National Election", "Vote in National Election",
                                "Participate in Campaign", "Participate in Campaign", "Participate in Campaign",
                                "Elected to Student Government", "Elected to Student Government", "Elected to Student Government"),
                   parinc= c("Low",
                             "Middle",
                             "High"),
                   effect = c(orglead.lis.eff, orglead.mis.eff, orglead.his.eff,
                              protest.lis.eff, protest.mis.eff, protest.his.eff,
                              passive.lis.eff, passive.mis.eff, passive.his.eff,
                              voteprez2.lis.eff, voteprez2.mis.eff, voteprez2.his.eff,
                              campaign.lis.eff, campaign.mis.eff, campaign.his.eff,
                              elected.lis.eff, elected.mis.eff, elected.his.eff ),
                   sig = c(orglead.lis.p, orglead.mis.p, orglead.his.p,
                           protest.lis.p, protest.mis.p, protest.his.p,
                           passive.lis.p, passive.mis.p, passive.his.p,
                           voteprez2.lis.p, voteprez2.mis.p, voteprez2.his.p,
                           campaign.lis.p, campaign.mis.p, campaign.his.p,
                           elected.lis.p, elected.mis.p, elected.his.p)) 

data$sig <- ifelse(data$sig >= .05, "n.s.",
                   ifelse(data$sig < .05 &
                            data$sig >= .01, "*",
                          ifelse(data$sig < .01 &
                                   data$sig >= .001, "**",
                                 ifelse(data$sig < .001, "***", NA))))

data$parinc <- factor(data$parinc , levels =c("Low", "Middle","High"))

p1<- ggplot(data[1:3,], aes(x=parinc, y=effect*100, fill=parinc)) +
  facet_grid(.~variable) +
  geom_bar(stat="identity") +
  ylab("Percentage Point Effect") +
  guides(fill=FALSE) +
  theme_bw() +
  theme(text = element_text(size=12, face="bold"), axis.title.x=element_blank()) +
  geom_hline(yintercept=0, linetype = "dashed") +
  scale_y_continuous(limits=c(-05, 20)) +
  geom_text(aes(x=parinc, y=ifelse(sig=="n.s.", 1.5, .5), 
                label=sig), 
            position = position_dodge(width=1))

p2<-ggplot(data[4:6,], aes(x=parinc, y=effect*100, fill=parinc)) +
  facet_grid(.~variable) +
  geom_bar(stat="identity") +
  guides(fill=FALSE) +
  theme_bw() +
  theme(text = element_text(size=12, face="bold"), axis.title.y=element_blank(), axis.title.x=element_blank()) +
  geom_hline(yintercept=0, linetype = "dashed") +
  scale_y_continuous(limits=c(-2.5, 10), breaks=c(0, 5, 10)) +
  geom_text(aes(x=parinc, y=ifelse(sig=="n.s.", .5, .3), 
                label=sig), 
            position = position_dodge(width=1))

p3<-ggplot(data[7:9,], aes(x=parinc, y=effect*100, fill=parinc)) +
  facet_grid(.~variable) +
  geom_bar(stat="identity") +
  guides(fill=FALSE) +
  theme_bw() +
  theme(text = element_text(size=12, face="bold"), axis.title.y=element_blank(), axis.title.x=element_blank()) +
  geom_hline(yintercept=0, linetype = "dashed") +
  scale_y_continuous(limits=c(-2.5, 10), breaks=c(0, 5, 10)) +
  geom_text(aes(x=parinc, y=ifelse(sig=="n.s.", .4, .3), 
                label=sig), 
            position = position_dodge(width=1))

p4<-ggplot(data[10:12,], aes(x=parinc, y=effect*100, fill=parinc)) +
  facet_grid(.~variable) +
  geom_bar(stat="identity") +
  ylab("Percentage Point Effect") +
  guides(fill=FALSE) +
  theme_bw() +
  theme(text = element_text(size=12, face="bold"), axis.title.x=element_blank()) +
  geom_hline(yintercept=0, linetype = "dashed") +
  scale_y_continuous(limits=c(-5, 10)) +
  geom_text(aes(x=parinc, y=ifelse(sig=="n.s.", .6, .4), 
                label=sig), 
            position = position_dodge(width=1))

p5<-ggplot(data[13:15,], aes(x=parinc, y=effect*100, fill=parinc)) +
  facet_grid(.~variable) +
  geom_bar(stat="identity") +
  guides(fill=FALSE) +
  theme_bw() +
  theme(text = element_text(size=12, face="bold"), axis.title.y=element_blank(), axis.title.x=element_blank()) +
  geom_hline(yintercept=0, linetype = "dashed") +
  scale_y_continuous(limits=c(-5, 10)) +
  geom_text(aes(x=parinc, y=ifelse(sig=="n.s.", 0.6, .4), 
                label=sig), 
            position = position_dodge(width=1))

p6<-ggplot(data[16:18,], aes(x=parinc, y=effect*100, fill=parinc)) +
  facet_grid(.~variable) +
  geom_bar(stat="identity") +
  guides(fill=FALSE) +
  theme_bw() +
  theme(text = element_text(size=12, face="bold"), axis.title.y=element_blank(), axis.title.x=element_blank()) +
  geom_hline(yintercept=0, linetype = "dashed") +
  scale_y_continuous(limits=c(-5, 10)) +
  geom_text(aes(x=parinc, y=ifelse(sig=="n.s.", .6, .5), 
                label=sig), 
            position = position_dodge(width=1))

grid.arrange(p1, p2, p3, p4, p5, p6, nrow=2)

############
# Figure 2 #
############

#############################
# Low self-selection groups #
#############################

#########################
# Passive participation #
#########################

passive.lis.close <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                            evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                            hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                            age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                            largesb + public + college + neast + south + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), data = data.lis[data.lis$closehome2==1,]) 

passive.lis.sports <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                             evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                             hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                             age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                             largesb + public + college + neast + south + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), data = data.lis[data.lis$athletics2==1,]) 

passive.lis.choice <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                             evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                             hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                             age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                             largesb + public + college + neast + south + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), data = data.lis[data.lis$firstchoice2==1,]) 

passive.re.lis.full.coefs.close <- data.frame(coef(summary(passive.lis.close)))
passive.re.lis.full.coefs.close$p.z <- 2 * (1 - pnorm(abs(passive.re.lis.full.coefs.close$t.value)))
passive.re.lis.full.coefs.close$p.z

passive.re.lis.full.coefs.sports <- data.frame(coef(summary(passive.lis.sports)))
passive.re.lis.full.coefs.sports$p.z <- 2 * (1 - pnorm(abs(passive.re.lis.full.coefs.sports$t.value)))
passive.re.lis.full.coefs.sports$p.z

passive.re.lis.full.coefs.choice <- data.frame(coef(summary(passive.lis.choice)))
passive.re.lis.full.coefs.choice$p.z <- 2 * (1 - pnorm(abs(passive.re.lis.full.coefs.choice$t.value)))
passive.re.lis.full.coefs.choice$p.z

modelvars <- c("passive_index_css_avg", "passive_index_tfs_avg", "affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black", "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs", "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south", "YEAR", "ACERECODE", "ace_year", "closehome2", "athletics2", "firstchoice2")

csscohort2 <- csscohort[complete.cases(csscohort[,modelvars]),]

data.lis.temp <- csscohort2[csscohort2$parinc == "Low-Income",]
data.lis.close.temp  <- csscohort2[csscohort2$parinc == "Low-Income" & csscohort2$closehome2 == 1, ]
data.lis.sports.temp  <- csscohort2[csscohort2$parinc == "Low-Income" & csscohort2$athletics2 == 1,]
data.lis.choice.temp  <- csscohort2[csscohort2$parinc == "Low-Income" & csscohort2$firstchoice2 == 1,]

passive.lis.close.p <- summary(passive.lis.close)$coefficients["factor(affcat)5",5] 

data.lis.close.temp$affcat <- 1
passive.lis.close.lis.1 <- mean(predict(passive.lis.close, data.lis.close.temp, re.form=NULL)) 
data.lis.close.temp$affcat <- 5
passive.lis.close.lis.5 <- mean(predict(passive.lis.close, data.lis.close.temp, re.form=NULL)) 
passive.lis.close.eff <- passive.lis.close.lis.5 - passive.lis.close.lis.1
passive.lis.close.eff

passive.lis.sports.p <- summary(passive.lis.sports)$coefficients["factor(affcat)5",5] 

data.lis.sports.temp$affcat <- 1
passive.lis.sports.lis.1 <- mean(predict(passive.lis.sports, data.lis.sports.temp, re.form=NULL, allow.new.levels = T)) 
data.lis.sports.temp$affcat <- 5
passive.lis.sports.lis.5 <- mean(predict(passive.lis.sports, data.lis.sports.temp, re.form=NULL)) 
passive.lis.sports.eff <- passive.lis.sports.lis.5 - passive.lis.sports.lis.1
passive.lis.sports.eff

passive.lis.choice.p <- summary(passive.lis.choice)$coefficients["factor(affcat)5",5] 

data.lis.choice.temp$affcat <- 1
passive.lis.choice.lis.1 <- mean(predict(passive.lis.choice, data.lis.choice.temp, re.form=NULL)) 
data.lis.choice.temp$affcat <- 5
passive.lis.choice.lis.5 <- mean(predict(passive.lis.choice, data.lis.choice.temp, re.form=NULL)) 
passive.lis.choice.eff <- passive.lis.choice.lis.5 - passive.lis.choice.lis.1
passive.lis.choice.eff

##########
# Voting #
##########

voteprez2.lis.close <- glmer(voteprez2 ~ polaffairs_tfs + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish 
                             + catholic + evangelical +otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                               hihispanicper + hiothraceper + hijewishper+ hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                               socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                               factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis[data.lis$closehome2==1,]) 

voteprez2.lis.sports <- glmer(voteprez2 ~ polaffairs_tfs + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                                otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                                hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                                socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                                factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data =  data.lis[data.lis$athletics2==1,]) 

voteprez2.lis.choice <- glmer(voteprez2 ~ polaffairs_tfs + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                                otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                                hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                                socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                                (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis[data.lis$firstchoice2==1,]) 

modelvars <- c("voteprez2", "polaffairs_tfs", "affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black", "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs", "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south", "YEAR", "ACERECODE", "ace_year", "closehome2", "athletics2", "firstchoice2")

csscohort2 <- csscohort[complete.cases(csscohort[,modelvars]),]

data.lis.temp <- csscohort2[csscohort2$parinc == "Low-Income",]
data.lis.close.temp  <- csscohort2[csscohort2$parinc == "Low-Income" & csscohort2$closehome2 == 1, ]
data.lis.sports.temp  <- csscohort2[csscohort2$parinc == "Low-Income" & csscohort2$athletics2 == 1,]
data.lis.choice.temp  <- csscohort2[csscohort2$parinc == "Low-Income" & csscohort2$firstchoice2 == 1,]

voteprez2.lis.close.p <- summary(voteprez2.lis.close)$coefficients["factor(affcat)5",4] 

data.lis.close.temp$affcat <- 1
voteprez2.lis.close.lis.1 <- mean(predict(voteprez2.lis.close, data.lis.close.temp, re.form=NULL, type = "response")) 
data.lis.close.temp$affcat <- 5
voteprez2.lis.close.lis.5 <- mean(predict(voteprez2.lis.close, data.lis.close.temp, re.form=NULL, type = "response")) 
voteprez2.lis.close.eff <- voteprez2.lis.close.lis.5 - voteprez2.lis.close.lis.1
voteprez2.lis.close.eff

voteprez2.lis.sports.p <- summary(voteprez2.lis.sports)$coefficients["factor(affcat)5",4] 

data.lis.sports.temp$affcat <- 1
voteprez2.lis.sports.lis.1 <- mean(predict(voteprez2.lis.sports, data.lis.sports.temp, re.form=NULL, type = "response")) 
data.lis.sports.temp$affcat <- 5
voteprez2.lis.sports.lis.5 <- mean(predict(voteprez2.lis.sports, data.lis.sports.temp, re.form=NULL, type = "response")) 
voteprez2.lis.sports.eff <- voteprez2.lis.sports.lis.5 - voteprez2.lis.sports.lis.1
voteprez2.lis.sports.eff

voteprez2.lis.choice.p <- summary(voteprez2.lis.choice)$coefficients["factor(affcat)5",4] 

data.lis.choice.temp$affcat <- 1
voteprez2.lis.choice.lis.1 <- mean(predict(voteprez2.lis.choice, data.lis.choice.temp, re.form=NULL, type = "response")) 
data.lis.choice.temp$affcat <- 5
voteprez2.lis.choice.lis.5 <- mean(predict(voteprez2.lis.choice, data.lis.choice.temp, re.form=NULL, type = "response")) 
voteprez2.lis.choice.eff <- voteprez2.lis.choice.lis.5 - voteprez2.lis.choice.lis.1
voteprez2.lis.choice.eff 

###############
# Campaigning #
###############

campaign.lis.close <- glmer(campaign_css ~ campaign_tfs + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                              otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                              hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                              socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                              factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis[data.lis$closehome2==1,]) 

modelvars <- c("campaign_css", "campaign_tfs", "affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black", "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs", "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south", "YEAR", "ACERECODE", "ace_year", "closehome2", "athletics2" )

csscohort2 <- csscohort[complete.cases(csscohort[,modelvars]),]

data.lis.temp <- csscohort2[csscohort2$parinc == "Low-Income",]
data.lis.close.temp  <- csscohort2[csscohort2$parinc == "Low-Income" & csscohort2$closehome2 == 1, ]
data.lis.sports.temp  <- csscohort2[csscohort2$parinc == "Low-Income" & csscohort2$athletics2 == 1,]
data.lis.choice.temp  <- csscohort2[csscohort2$parinc == "Low-Income" & csscohort2$firstchoice2 == 1,]

campaign.lis.close.p <- summary(campaign.lis.close)$coefficients["factor(affcat)5",4] 

data.lis.close.temp$affcat <- 1
campaign.lis.close.lis.1 <- mean(predict(campaign.lis.close, data.lis.close.temp, re.form=NULL, type = "response")) 
data.lis.close.temp$affcat <- 5
campaign.lis.close.lis.5 <- mean(predict(campaign.lis.close, data.lis.close.temp, re.form=NULL, type = "response")) 
campaign.lis.close.eff <- campaign.lis.close.lis.5 - campaign.lis.close.lis.1
campaign.lis.close.p

#############################
# Elected to Student Office #
#############################

elected.lis.close <- glmer(elected01_gov ~ commlead_tfs + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                             otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                             hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                             socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                             factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis[data.lis$closehome2==1,]) 

elected.lis.sports <- glmer(elected01_gov ~ commlead_tfs + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                              otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                              hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                              socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                              factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis[data.lis$athletics2==1,]) 

modelvars <- c("elected01_gov", "commlead_tfs", "affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black", "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs", "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south", "YEAR", "ACERECODE", "ace_year", "closehome2", "athletics2")

csscohort2 <- csscohort[complete.cases(csscohort[,modelvars]),]

data.lis.temp <- csscohort2[csscohort2$parinc == "Low-Income",]
data.lis.close.temp  <- csscohort2[csscohort2$parinc == "Low-Income" & csscohort2$closehome2 == 1, ]
data.lis.sports.temp  <- csscohort2[csscohort2$parinc == "Low-Income" & csscohort2$athletics2 == 1,]
data.lis.choice.temp  <- csscohort2[csscohort2$parinc == "Low-Income" & csscohort2$firstchoice2 == 1,]

elected.lis.close.p <- summary(elected.lis.close)$coefficients["factor(affcat)5",4] 

data.lis.close.temp$affcat <- 1
elected.lis.close.lis.1 <- mean(predict(elected.lis.close, data.lis.close.temp, re.form=NULL, type = "response")) 
data.lis.close.temp$affcat <- 5
elected.lis.close.lis.5 <- mean(predict(elected.lis.close, data.lis.close.temp, re.form=NULL, type = "response")) 
elected.lis.close.eff <- elected.lis.close.lis.5 - elected.lis.close.lis.1
elected.lis.close.eff

elected.lis.sports.p <- summary(elected.lis.sports)$coefficients["factor(affcat)5",4] 

data.lis.sports.temp$affcat <- 1
elected.lis.sports.lis.1 <- mean(predict(elected.lis.sports, data.lis.sports.temp, re.form=NULL, type = "response")) 
data.lis.sports.temp$affcat <- 5
elected.lis.sports.lis.5 <- mean(predict(elected.lis.sports, data.lis.sports.temp, re.form=NULL, type = "response")) 
elected.lis.sports.eff <- elected.lis.sports.lis.5 - elected.lis.sports.lis.1
elected.lis.sports.eff

##################################
# Leader of Student Organization #
##################################

orglead.lis.close <- glmer(orglead01 ~ commlead_tfs + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                             otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                             hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                             socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                             factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), 
                             data = data.lis[data.lis$closehome2==1,]) 

orglead.lis.sports <- glmer(orglead01 ~ commlead_tfs + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                              otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                              hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                              socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                              factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), 
                              data = data.lis[data.lis$athletics2==1,]) 

orglead.lis.choice <- glmer(orglead01 ~ commlead_tfs + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                              otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                              hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                              socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                              factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), 
                              data = data.lis[data.lis$firstchoice2==1,]) 

modelvars <- c("orglead01", "commlead_tfs", "affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black", "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs", "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south", "YEAR", "ACERECODE", "ace_year", "closehome2", "athletics2", "firstchoice2")

csscohort2 <- csscohort[complete.cases(csscohort[,modelvars]),]

data.lis.temp <- csscohort2[csscohort2$parinc == "Low-Income",]
data.lis.close.temp  <- csscohort2[csscohort2$parinc == "Low-Income" & csscohort2$closehome2 == 1, ]
data.lis.sports.temp  <- csscohort2[csscohort2$parinc == "Low-Income" & csscohort2$athletics2 == 1,]
data.lis.choice.temp  <- csscohort2[csscohort2$parinc == "Low-Income" & csscohort2$firstchoice2 == 1,]

orglead.lis.close.p <- summary(orglead.lis.close)$coefficients["factor(affcat)5",4] 

data.lis.close.temp$affcat <- 1
orglead.lis.close.lis.1 <- mean(predict(orglead.lis.close, data.lis.close.temp, re.form=NULL, type = "response")) 
data.lis.close.temp$affcat <- 5
orglead.lis.close.lis.5 <- mean(predict(orglead.lis.close, data.lis.close.temp, re.form=NULL, type = "response")) 
orglead.lis.close.eff <- orglead.lis.close.lis.5 - orglead.lis.close.lis.1
orglead.lis.close.eff

orglead.lis.sports.p <- summary(orglead.lis.sports)$coefficients["factor(affcat)5",4] 

data.lis.sports.temp$affcat <- 1
orglead.lis.sports.lis.1 <- mean(predict(orglead.lis.sports, data.lis.sports.temp, re.form=NULL, type = "response")) 
data.lis.sports.temp$affcat <- 5
orglead.lis.sports.lis.5 <- mean(predict(orglead.lis.sports, data.lis.sports.temp, re.form=NULL, type = "response")) 
orglead.lis.sports.eff <- orglead.lis.sports.lis.5 - orglead.lis.sports.lis.1
orglead.lis.sports.eff

orglead.lis.choice.p <- summary(orglead.lis.choice)$coefficients["factor(affcat)5",4] 

data.lis.choice.temp$affcat <- 1
orglead.lis.choice.lis.1 <- mean(predict(orglead.lis.choice, data.lis.choice.temp, re.form=NULL, type = "response")) 
data.lis.choice.temp$affcat <- 5
orglead.lis.choice.lis.5 <- mean(predict(orglead.lis.choice, data.lis.choice.temp, re.form=NULL, type = "response")) 
orglead.lis.choice.eff <- orglead.lis.choice.lis.5 - orglead.lis.choice.lis.1
orglead.lis.choice.eff

#################
# Protest Index #
#################

protest.lis.close <- glmer(protestindex_css ~ protest_tfs + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                             otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                             hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                             socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                             factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis[data.lis$closehome2==1,]) 

modelvars <- c("protestindex_css", "protest_tfs", "affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black", "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs", "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south", "YEAR", "ACERECODE", "ace_year", "closehome2")

csscohort2 <- csscohort[complete.cases(csscohort[,modelvars]),]

data.lis.temp <- csscohort2[csscohort2$parinc == "Low-Income",]
data.lis.close.temp  <- csscohort2[csscohort2$parinc == "Low-Income" & csscohort2$closehome2 == 1, ]
data.lis.sports.temp  <- csscohort2[csscohort2$parinc == "Low-Income" & csscohort2$athletics2 == 1,]
data.lis.choice.temp  <- csscohort2[csscohort2$parinc == "Low-Income" & csscohort2$firstchoice2 == 1,]

protest.lis.close.p <- summary(protest.lis.close)$coefficients["factor(affcat)5",4] 

data.lis.close.temp$affcat <- 1
protest.lis.close.lis.1 <- mean(predict(protest.lis.close, data.lis.close.temp, re.form=NULL, type = "response")) 
data.lis.close.temp$affcat <- 5
protest.lis.close.lis.5 <- mean(predict(protest.lis.close, data.lis.close.temp, re.form=NULL, type = "response")) 
protest.lis.close.eff <- protest.lis.close.lis.5 - protest.lis.close.lis.1
protest.lis.close.eff

###################
# Create Figure 2 #
###################

data = data.frame (variable = c("Lead Student Organization", "Lead Student Organization", "Lead Student Organization", "Lead Student Organization",
                                "Protest Involvement", "Protest Involvement", "Protest Involvement", "Protest Involvement",
                                "Passive Engagement Index", "Passive Engagement Index", "Passive Engagement Index", "Passive Engagement Index",
                                "Vote in National Election", "Vote in National Election", "Vote in National Election", "Vote in National Election",
                                "Participate in Campaign", "Participate in Campaign", "Participate in Campaign", "Participate in Campaign",
                                "Elected to Student Government", "Elected to Student Government", "Elected to Student Government", "Elected to Student Government"),
                   parinc= c("All LIS", "Home", "Athlete", "Not\n1st-Choice"),
                   effect = c(orglead.lis.eff, orglead.lis.close.eff, orglead.lis.sports.eff, orglead.lis.choice.eff,
                              protest.lis.eff, protest.lis.close.eff, 0, 0,
                              passive.lis.eff, passive.lis.close.eff, passive.lis.sports.eff, passive.lis.choice.eff,
                              voteprez2.lis.eff, voteprez2.lis.close.eff, voteprez2.lis.sports.eff, voteprez2.lis.choice.eff,
                              campaign.lis.eff, campaign.lis.close.eff, 0, 0,
                              elected.lis.eff, elected.lis.close.eff, elected.lis.sports.eff, 0),
                   sig = c(orglead.lis.p,  orglead.lis.close.p,  orglead.lis.sports.p, orglead.lis.choice.p,
                           protest.lis.p, protest.lis.close.p, 10, 10,
                           passive.lis.p, passive.lis.close.p, passive.lis.sports.p, passive.lis.choice.p,
                           voteprez2.lis.p, voteprez2.lis.close.p, voteprez2.lis.sports.p, voteprez2.lis.choice.p,
                           campaign.lis.p, campaign.lis.close.p, 10, 10,
                           elected.lis.p, elected.lis.close.p, elected.lis.sports.p, 10)) 

data$sig <- ifelse(data$sig == 10, "INSUFF.\nDATA",
                   ifelse(data$sig >= .05 & data$sig != 10, "n.s",
                          ifelse(data$sig < .05 &
                                   data$sig >= .01, "*",
                                 ifelse(data$sig < .01 &
                                          data$sig >= .001, "**",
                                        ifelse(data$sig < .001, "***", NA)))))

data$parinc <- factor(data$parinc , levels =c("All LIS", "Home", "Athlete", "Not\n1st-Choice"))


p1<- ggplot(data[1:4,], aes(x=parinc, y=effect*100, fill=parinc)) +
  facet_grid(.~variable) +
  geom_bar(stat="identity") +
  ylab("Percentage Point Effect") +
  guides(fill=FALSE) +
  theme_bw() +
  theme(text = element_text(size=12, face="bold"), axis.title.x=element_blank()) +
  geom_hline(yintercept=0, linetype = "dashed") +
  scale_y_continuous(limits=c(-05, 47)) +
  geom_text(aes(x=parinc, y=ifelse(sig=="n.s", 1.8, .8), 
                label=sig), 
            position = position_dodge(width=1))

p2<-ggplot(data[5:8,], aes(x=parinc, y=effect*100, fill=parinc)) +
  facet_grid(.~variable) +
  geom_bar(stat="identity") +
  guides(fill=FALSE) +
  theme_bw() +
  theme(text = element_text(size=12, face="bold"), axis.title.y=element_blank(), axis.title.x=element_blank()) +
  geom_hline(yintercept=0, linetype = "dashed") +
  scale_y_continuous(limits=c(-1, 10)) +
  geom_text(aes(x=parinc, y=ifelse(sig=="n.s", .4, ifelse(sig=="INSUFF.\nDATA", 1.0, .3)), 
                label=sig), 
            position = position_dodge(width=1))

p3<-ggplot(data[9:12,], aes(x=parinc, y=effect*100, fill=parinc)) +
  facet_grid(.~variable) +
  geom_bar(stat="identity") +
  guides(fill=FALSE) +
  theme_bw() +
  theme(text = element_text(size=12, face="bold"), axis.title.y=element_blank(), axis.title.x=element_blank()) +
  geom_hline(yintercept=0, linetype = "dashed") +
  scale_y_continuous(limits=c(-1, 10)) +
  geom_text(aes(x=parinc, y=ifelse(sig=="n.s", .4, .3), 
                label=sig), 
            position = position_dodge(width=1))

p4<-ggplot(data[13:16,], aes(x=parinc, y=effect*100, fill=parinc)) +
  facet_grid(.~variable) +
  geom_bar(stat="identity") +
  ylab("Percentage Point Effect") +
  guides(fill=FALSE) +
  theme_bw() +
  theme(text = element_text(size=12, face="bold"), axis.title.x=element_blank()) +
  geom_hline(yintercept=0, linetype = "dashed") +
  scale_y_continuous(limits=c(-2, 15)) +
  geom_text(aes(x=parinc, y=ifelse(sig=="n.s", .8, .4), 
                label=sig), 
            position = position_dodge(width=1))

p5<-ggplot(data[17:20,], aes(x=parinc, y=effect*100, fill=parinc)) +
  facet_grid(.~variable) +
  geom_bar(stat="identity") +
  guides(fill=FALSE) +
  theme_bw() +
  theme(text = element_text(size=12, face="bold"), axis.title.y=element_blank(), axis.title.x=element_blank()) +
  geom_hline(yintercept=0, linetype = "dashed") +
  scale_y_continuous(limits=c(-2, 15)) +
  geom_text(aes(x=parinc, y=ifelse(sig=="n.s", .8, ifelse(sig=="INSUFF.\nDATA", 1.6, .3)), 
                label=sig), 
            position = position_dodge(width=1))

p6<-ggplot(data[21:24,], aes(x=parinc, y=effect*100, fill=parinc)) +
  facet_grid(.~variable) +
  geom_bar(stat="identity") +
  guides(fill=FALSE) +
  theme_bw() +
  theme(text = element_text(size=12, face="bold"), axis.title.y=element_blank(), axis.title.x=element_blank()) +
  geom_hline(yintercept=0, linetype = "dashed") +
  scale_y_continuous(limits=c(-12.6, 15)) +
  geom_text(aes(x=parinc, y=ifelse(sig=="n.s", .8,  ifelse(sig=="INSUFF.\nDATA", 2.3, .3)), 
                label=sig), 
            position = position_dodge(width=1))

grid.arrange(p1, p2, p3, p4, p5, p6, nrow=2)

############
# Table 1 #
############

##########################
## Intervening Analysis
##########################

# Psychological Mechanism

emohealth.lis <- lmer(emohealth_css ~ emohealth_tfs + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                        evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                        hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                        age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                        largesb + public + college + neast + south + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), data = data.lis)

emohealth.mis <- lmer(emohealth_css ~ emohealth_tfs + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                        evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                        hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                        age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                        largesb + public + college + neast + south + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), data = data.mis)

emohealth.his <- lmer(emohealth_css ~ emohealth_tfs + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                        evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                        hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                        age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                        largesb + public + college + neast + south + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), data = data.his)

modelvars <- c("emohealth_css", "emohealth_tfs", "affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black", "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs", "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south", "YEAR", "ACERECODE", "ace_year")

csscohort2 <- csscohort[complete.cases(csscohort[,modelvars]),]

data.lis.temp <- csscohort2[csscohort2$parinc == "Low-Income",]
data.mis.temp  <- csscohort2[csscohort2$parinc == "Middle-Income",]
data.his.temp  <- csscohort2[csscohort2$parinc == "High-Income",]

emohealth.lis.p <- summary(emohealth.lis)$coefficients["factor(affcat)5",5] 

data.lis.temp$affcat <- 1
emohealth.lis.pred.1 <- mean(predict(emohealth.lis, data.lis.temp, re.form=NULL)) 
data.lis.temp$affcat <- 5
emohealth.lis.pred.5 <- mean(predict(emohealth.lis, data.lis.temp, re.form=NULL)) 
emohealth.lis.eff <- emohealth.lis.pred.5 - emohealth.lis.pred.1

emohealth.mis.p <- summary(emohealth.mis)$coefficients["factor(affcat)5",5] 

data.mis.temp$affcat <- 1
emohealth.mis.pred.1 <- mean(predict(emohealth.mis, data.mis.temp, re.form=NULL)) 
data.mis.temp$affcat <- 5
emohealth.mis.pred.5 <- mean(predict(emohealth.mis, data.mis.temp, re.form=NULL)) 
emohealth.mis.eff <- emohealth.mis.pred.5 - emohealth.mis.pred.1

emohealth.his.p <- summary(emohealth.his)$coefficients["factor(affcat)5",5] 

data.his.temp$affcat <- 1
emohealth.his.pred.1 <- mean(predict(emohealth.his, data.his.temp, re.form=NULL)) 
data.his.temp$affcat <- 5
emohealth.his.pred.5 <- mean(predict(emohealth.his, data.his.temp, re.form=NULL)) 
emohealth.his.eff <- emohealth.his.pred.5 - emohealth.his.pred.1

motivationlead.lis <- lmer(motivationlead_css ~ motivationlead_tfs + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                             evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                             hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                             age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                             largesb + public + college + neast + south + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), data = data.lis)

motivationlead.mis <- lmer(motivationlead_css ~ motivationlead_tfs + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                             evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                             hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                             age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                             largesb + public + college + neast + south + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), data = data.mis)

motivationlead.his <- lmer(motivationlead_css ~ motivationlead_tfs + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                             evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                             hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                             age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                             largesb + public + college + neast + south + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), data = data.his)

modelvars <- c("motivationlead_css", "motivationlead_tfs", "affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black", "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs", "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south", "YEAR", "ACERECODE", "ace_year")

csscohort2 <- csscohort[complete.cases(csscohort[,modelvars]),]

data.lis.temp <- csscohort2[csscohort2$parinc == "Low-Income",]
data.mis.temp  <- csscohort2[csscohort2$parinc == "Middle-Income",]
data.his.temp  <- csscohort2[csscohort2$parinc == "High-Income",]

motivationlead.lis.p <- summary(motivationlead.lis)$coefficients["factor(affcat)5",5] 

data.lis.temp$affcat <- 1
motivationlead.lis.pred.1 <- mean(predict(motivationlead.lis, data.lis.temp, re.form=NULL)) 
data.lis.temp$affcat <- 5
motivationlead.lis.pred.5 <- mean(predict(motivationlead.lis, data.lis.temp, re.form=NULL)) 
motivationlead.lis.eff <- motivationlead.lis.pred.5 - motivationlead.lis.pred.1

motivationlead.mis.p <- summary(motivationlead.mis)$coefficients["factor(affcat)5",5] 

data.mis.temp$affcat <- 1
motivationlead.mis.pred.1 <- mean(predict(motivationlead.mis, data.mis.temp, re.form=NULL)) 
data.mis.temp$affcat <- 5
motivationlead.mis.pred.5 <- mean(predict(motivationlead.mis, data.mis.temp, re.form=NULL)) 
motivationlead.mis.eff <- motivationlead.mis.pred.5 - motivationlead.mis.pred.1

motivationlead.his.p <- summary(motivationlead.his)$coefficients["factor(affcat)5",5] 

data.his.temp$affcat <- 1
motivationlead.his.pred.1 <- mean(predict(motivationlead.his, data.his.temp, re.form=NULL)) 
data.his.temp$affcat <- 5
motivationlead.his.pred.5 <- mean(predict(motivationlead.his, data.his.temp, re.form=NULL)) 
motivationlead.his.eff <- motivationlead.his.pred.5 - motivationlead.his.pred.1

# Academic Mechanism

academcomp.lis <- lmer(academcomp_css ~ academcomp_tfs + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                         evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                         hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                         age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                         largesb + public + college + neast + south + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), data = data.lis)

academcomp.mis <- lmer(academcomp_css ~ academcomp_tfs + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                         evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                         hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                         age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                         largesb + public + college + neast + south + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), data = data.mis)

academcomp.his <- lmer(academcomp_css ~ academcomp_tfs + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                         evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                         hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                         age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                         largesb + public + college + neast + south + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), data = data.his)

modelvars <- c("academcomp_css", "academcomp_tfs", "affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black", "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs", "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south", "YEAR", "ACERECODE", "ace_year")

csscohort2 <- csscohort[complete.cases(csscohort[,modelvars]),]

data.lis.temp <- csscohort2[csscohort2$parinc == "Low-Income",]
data.mis.temp  <- csscohort2[csscohort2$parinc == "Middle-Income",]
data.his.temp  <- csscohort2[csscohort2$parinc == "High-Income",]

academcomp.lis.p <- summary(academcomp.lis)$coefficients["factor(affcat)5",5] 

data.lis.temp$affcat <- 1
academcomp.lis.pred.1 <- mean(predict(academcomp.lis, data.lis.temp, re.form=NULL)) 
data.lis.temp$affcat <- 5
academcomp.lis.pred.5 <- mean(predict(academcomp.lis, data.lis.temp, re.form=NULL)) 
academcomp.lis.eff <- academcomp.lis.pred.5 - academcomp.lis.pred.1

academcomp.mis.p <- summary(academcomp.mis)$coefficients["factor(affcat)5",5] 

data.mis.temp$affcat <- 1
academcomp.mis.pred.1 <- mean(predict(academcomp.mis, data.mis.temp, re.form=NULL)) 
data.mis.temp$affcat <- 5
academcomp.mis.pred.5 <- mean(predict(academcomp.mis, data.mis.temp, re.form=NULL)) 
academcomp.mis.eff <- academcomp.mis.pred.5 - academcomp.mis.pred.1

academcomp.his.p <- summary(academcomp.his)$coefficients["factor(affcat)5",5] 

data.his.temp$affcat <- 1
academcomp.his.pred.1 <- mean(predict(academcomp.his, data.his.temp, re.form=NULL)) 
data.his.temp$affcat <- 5
academcomp.his.pred.5 <- mean(predict(academcomp.his, data.his.temp, re.form=NULL)) 
academcomp.his.eff <- academcomp.his.pred.5 - academcomp.his.pred.1

# Social Mechanism

soccon.lis <- lmer(soccon_css ~ soccon_tfs + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                     evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                     hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                     age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                     largesb + public + college + neast + south + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), data = data.lis)

soccon.mis <- lmer(soccon_css ~ soccon_tfs + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                     evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                     hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                     age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                     largesb + public + college + neast + south + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), data = data.mis)

soccon.his <- lmer(soccon_css ~ soccon_tfs + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                     evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                     hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                     age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                     largesb + public + college + neast + south + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), data = data.his)

socsatis.lis <- lmer(socsatis_css ~ socmarg_tfs + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                       evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                       hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                       age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                       largesb + public + college + neast + south + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), data = data.lis)

socsatis.mis <- lmer(socsatis_css ~ socmarg_tfs + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                       evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                       hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                       age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                       largesb + public + college + neast + south + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), data = data.mis)

socsatis.his <- lmer(socsatis_css ~ socmarg_tfs + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                       evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                       hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                       age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                       largesb + public + college + neast + south + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), data = data.his)

modelvars <- c("socsatis_css", "socmarg_tfs", "affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black", "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs", "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south", "YEAR", "ACERECODE", "ace_year")

csscohort2 <- csscohort[complete.cases(csscohort[,modelvars]),]

data.lis.temp <- csscohort2[csscohort2$parinc == "Low-Income",]
data.mis.temp  <- csscohort2[csscohort2$parinc == "Middle-Income",]
data.his.temp  <- csscohort2[csscohort2$parinc == "High-Income",]

socsatis.lis.p <- summary(socsatis.lis)$coefficients["factor(affcat)5",5] 

data.lis.temp$affcat <- 1
socsatis.lis.pred.1 <- mean(predict(socsatis.lis, data.lis.temp, re.form=NULL)) 
data.lis.temp$affcat <- 5
socsatis.lis.pred.5 <- mean(predict(socsatis.lis, data.lis.temp, re.form=NULL)) 
socsatis.lis.eff <- socsatis.lis.pred.5 - socsatis.lis.pred.1

socsatis.mis.p <- summary(socsatis.mis)$coefficients["factor(affcat)5",5] 

data.mis.temp$affcat <- 1
socsatis.mis.pred.1 <- mean(predict(socsatis.mis, data.mis.temp, re.form=NULL)) 
data.mis.temp$affcat <- 5
socsatis.mis.pred.5 <- mean(predict(socsatis.mis, data.mis.temp, re.form=NULL)) 
socsatis.mis.eff <- socsatis.mis.pred.5 - socsatis.mis.pred.1

socsatis.his.p <- summary(socsatis.his)$coefficients["factor(affcat)5",5] 

data.his.temp$affcat <- 1
socsatis.his.pred.1 <- mean(predict(socsatis.his, data.his.temp, re.form=NULL)) 
data.his.temp$affcat <- 5
socsatis.his.pred.5 <- mean(predict(socsatis.his, data.his.temp, re.form=NULL)) 
socsatis.his.eff <- socsatis.his.pred.5 - socsatis.his.pred.1


modelvars <- c("soccon_css", "soccon_tfs", "affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black", "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs", "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south", "YEAR", "ACERECODE", "ace_year")

csscohort2 <- csscohort[complete.cases(csscohort[,modelvars]),]

data.lis.temp <- csscohort2[csscohort2$parinc == "Low-Income",]
data.mis.temp  <- csscohort2[csscohort2$parinc == "Middle-Income",]
data.his.temp  <- csscohort2[csscohort2$parinc == "High-Income",]

soccon.lis.p <- summary(soccon.lis)$coefficients["factor(affcat)5",5] 

data.lis.temp$affcat <- 1
soccon.lis.pred.1 <- mean(predict(soccon.lis, data.lis.temp, re.form=NULL)) 
data.lis.temp$affcat <- 5
soccon.lis.pred.5 <- mean(predict(soccon.lis, data.lis.temp, re.form=NULL)) 
soccon.lis.eff <- soccon.lis.pred.5 - soccon.lis.pred.1

soccon.mis.p <- summary(soccon.mis)$coefficients["factor(affcat)5",5] 

data.mis.temp$affcat <- 1
soccon.mis.pred.1 <- mean(predict(soccon.mis, data.mis.temp, re.form=NULL)) 
data.mis.temp$affcat <- 5
soccon.mis.pred.5 <- mean(predict(soccon.mis, data.mis.temp, re.form=NULL)) 
soccon.mis.eff <- soccon.mis.pred.5 - soccon.mis.pred.1

soccon.his.p <- summary(soccon.his)$coefficients["factor(affcat)5",5] 

data.his.temp$affcat <- 1
soccon.his.pred.1 <- mean(predict(soccon.his, data.his.temp, re.form=NULL)) 
data.his.temp$affcat <- 5
soccon.his.pred.5 <- mean(predict(soccon.his, data.his.temp, re.form=NULL)) 
soccon.his.eff <- soccon.his.pred.5 - soccon.his.pred.1

# Financial Mechanism

hpwworking.lis <- lmer(hpwworking ~ aidpartimeon + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                         evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                         hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                         age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                         largesb + public + college + neast + south + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), data = data.lis)

hpwworking.mis <- lmer(hpwworking ~ aidpartimeon + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                         evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                         hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                         age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                         largesb + public + college + neast + south + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), data = data.mis)

hpwworking.his <- lmer(hpwworking ~ aidpartimeon + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                         evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                         hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                         age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                         largesb + public + college + neast + south + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), data = data.his)

modelvars <- c("hpwworking", "aidpartimeon", "affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black", "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs", "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south", "YEAR", "ACERECODE", "ace_year")

csscohort2 <- csscohort[complete.cases(csscohort[,modelvars]),]

data.lis.temp <- csscohort2[csscohort2$parinc == "Low-Income",]
data.mis.temp  <- csscohort2[csscohort2$parinc == "Middle-Income",]
data.his.temp  <- csscohort2[csscohort2$parinc == "High-Income",]

hpwworking.lis.p <- summary(hpwworking.lis)$coefficients["factor(affcat)5",5] 

data.lis.temp$affcat <- 1
hpwworking.lis.pred.1 <- mean(predict(hpwworking.lis, data.lis.temp, re.form=NULL)) 
data.lis.temp$affcat <- 5
hpwworking.lis.pred.5 <- mean(predict(hpwworking.lis, data.lis.temp, re.form=NULL)) 
hpwworking.lis.eff <- hpwworking.lis.pred.5 - hpwworking.lis.pred.1

hpwworking.mis.p <- summary(hpwworking.mis)$coefficients["factor(affcat)5",5] 

data.mis.temp$affcat <- 1
hpwworking.mis.pred.1 <- mean(predict(hpwworking.mis, data.mis.temp, re.form=NULL)) 
data.mis.temp$affcat <- 5
hpwworking.mis.pred.5 <- mean(predict(hpwworking.mis, data.mis.temp, re.form=NULL)) 
hpwworking.mis.eff <- hpwworking.mis.pred.5 - hpwworking.mis.pred.1

hpwworking.his.p <- summary(hpwworking.his)$coefficients["factor(affcat)5",5] 

data.his.temp$affcat <- 1
hpwworking.his.pred.1 <- mean(predict(hpwworking.his, data.his.temp, re.form=NULL)) 
data.his.temp$affcat <- 5
hpwworking.his.pred.5 <- mean(predict(hpwworking.his, data.his.temp, re.form=NULL)) 
hpwworking.his.eff <- hpwworking.his.pred.5 - hpwworking.his.pred.1

# Create Aggregate Intervening Variables

yrs <- 1989:2009
cohortdata <- list()
for(i in 1:length(yrs)){
  affcat <- tapply(csscohort$affcat[csscohort$YEAR_TFS == yrs[i]], 
                   csscohort$ACERECODE[csscohort$YEAR_TFS == yrs[i]], mean, na.rm = T)
  hitestscoreper <- tapply(csscohort$hitestscoreper[csscohort$YEAR_TFS == yrs[i]], 
                           csscohort$ACERECODE[csscohort$YEAR_TFS == yrs[i]], mean, na.rm = T)
  hiasianper <- tapply(csscohort$hiasianper[csscohort$YEAR_TFS == yrs[i]], 
                       csscohort$ACERECODE[csscohort$YEAR_TFS == yrs[i]], mean, na.rm = T)
  hihispanicper <- tapply(csscohort$hihispanicper[csscohort$YEAR_TFS == yrs[i]], 
                          csscohort$ACERECODE[csscohort$YEAR_TFS == yrs[i]], mean, na.rm = T)
  hiothraceper <- tapply(csscohort$hiothraceper[csscohort$YEAR_TFS == yrs[i]], 
                         csscohort$ACERECODE[csscohort$YEAR_TFS == yrs[i]], mean, na.rm = T)
  hijewishper <- tapply(csscohort$hijewishper[csscohort$YEAR_TFS == yrs[i]], 
                        csscohort$ACERECODE[csscohort$YEAR_TFS == yrs[i]], mean, na.rm = T)
  hicatholicper <- tapply(csscohort$hicatholicper[csscohort$YEAR_TFS == yrs[i]], 
                          csscohort$ACERECODE[csscohort$YEAR_TFS == yrs[i]], mean, na.rm = T)
  hievangelicalper <- tapply(csscohort$hievangelicalper[csscohort$YEAR_TFS == yrs[i]], 
                             csscohort$ACERECODE[csscohort$YEAR_TFS == yrs[i]], mean, na.rm = T)
  hiotherornoreligper <- tapply(csscohort$hiotherornoreligper[csscohort$YEAR_TFS == yrs[i]], 
                                csscohort$ACERECODE[csscohort$YEAR_TFS == yrs[i]], mean, na.rm = T)
  notenglishfirstper <- tapply(csscohort$notenglishfirstper[csscohort$YEAR_TFS == yrs[i]], 
                               csscohort$ACERECODE[csscohort$YEAR_TFS == yrs[i]], mean, na.rm = T)
  age17orlessper <- tapply(csscohort$age17orlessper[csscohort$YEAR_TFS == yrs[i]], 
                           csscohort$ACERECODE[csscohort$YEAR_TFS == yrs[i]], mean, na.rm = T)
  age20per <- tapply(csscohort$age20per[csscohort$YEAR_TFS == yrs[i]], 
                     csscohort$ACERECODE[csscohort$YEAR_TFS == yrs[i]], mean, na.rm = T)
  socscitfsper <- tapply(csscohort$socscitfsper[csscohort$YEAR_TFS == yrs[i]], 
                         csscohort$ACERECODE[csscohort$YEAR_TFS == yrs[i]], mean, na.rm = T)
  age19per <- tapply(csscohort$age19per[csscohort$YEAR_TFS == yrs[i]], 
                     csscohort$ACERECODE[csscohort$YEAR_TFS == yrs[i]], mean, na.rm = T)
  humantfsper <- tapply(csscohort$humantfsper[csscohort$YEAR_TFS == yrs[i]], 
                        csscohort$ACERECODE[csscohort$YEAR_TFS == yrs[i]], mean, na.rm = T)
  sciencetfsper <- tapply(csscohort$sciencetfsper[csscohort$YEAR_TFS == yrs[i]], 
                          csscohort$ACERECODE[csscohort$YEAR_TFS == yrs[i]], mean, na.rm = T)
  businesstfsper <- tapply(csscohort$businesstfsper[csscohort$YEAR_TFS == yrs[i]], 
                           csscohort$ACERECODE[csscohort$YEAR_TFS == yrs[i]], mean, na.rm = T)
  makemoneyvimpper <- tapply(csscohort$makemoneyvimpper[csscohort$YEAR_TFS == yrs[i]], 
                             csscohort$ACERECODE[csscohort$YEAR_TFS == yrs[i]], mean, na.rm = T)
  mostlyfemale <- tapply(csscohort$mostlyfemale[csscohort$YEAR_TFS == yrs[i]], 
                         csscohort$ACERECODE[csscohort$YEAR_TFS == yrs[i]], mean, na.rm = T)
  mostlyblack <- tapply(csscohort$mostlyblack[csscohort$YEAR_TFS == yrs[i]], 
                        csscohort$ACERECODE[csscohort$YEAR_TFS == yrs[i]], mean, na.rm = T)
  largesb <- tapply(csscohort$largesb[csscohort$YEAR_TFS == yrs[i]], 
                    csscohort$ACERECODE[csscohort$YEAR_TFS == yrs[i]], mean, na.rm = T)
  public <- tapply(csscohort$public[csscohort$YEAR_TFS == yrs[i]], 
                   csscohort$ACERECODE[csscohort$YEAR_TFS == yrs[i]], mean, na.rm = T)
  college <- tapply(csscohort$college[csscohort$YEAR_TFS == yrs[i]], 
                    csscohort$ACERECODE[csscohort$YEAR_TFS == yrs[i]], mean, na.rm = T)
  neast <- tapply(csscohort$neast[csscohort$YEAR_TFS == yrs[i]], 
                  csscohort$ACERECODE[csscohort$YEAR_TFS == yrs[i]], mean, na.rm = T)
  south <- tapply(csscohort$south[csscohort$YEAR_TFS == yrs[i]], 
                  csscohort$ACERECODE[csscohort$YEAR_TFS == yrs[i]], mean, na.rm = T)
  passive_tfs_cohort <- tapply(csscohort$passive_index_tfs_avg[csscohort$YEAR_TFS == yrs[i]], 
                               csscohort$ACERECODE[csscohort$YEAR_TFS == yrs[i]], mean, na.rm = T)
  collaidratio_cohort <- tapply(data.lis$collaidratio[data.lis$YEAR_TFS == yrs[i]], 
                                data.lis$ACERECODE[data.lis$YEAR_TFS == yrs[i]], mean, na.rm = T)
  passive_tfs_cohort.n <- tapply(csscohort$passive_index_tfs_avg[csscohort$YEAR_TFS == yrs[i] | csscohort$YEAR_TFS == yrs[i] - 1], 
                                 csscohort$ACERECODE[csscohort$YEAR_TFS == yrs[i] | csscohort$YEAR_TFS == yrs[i] - 1], length)
  collaidratio_cohort.n <- tapply(data.lis$collaidratio[csscohort$YEAR_TFS == yrs[i] | data.lis$YEAR_TFS == yrs[i] - 1], 
                                  data.lis$ACERECODE[csscohort$YEAR_TFS == yrs[i] | data.lis$YEAR_TFS == yrs[i] - 1], length)
  cohort <- as.data.frame(cbind(affcat, hitestscoreper, hiasianper, hihispanicper, hiothraceper, hijewishper, hicatholicper, hievangelicalper, hiotherornoreligper,
                                notenglishfirstper, age17orlessper, age19per, age20per, socscitfsper, humantfsper, sciencetfsper, businesstfsper, makemoneyvimpper, 
                                mostlyfemale, mostlyblack, largesb, public, college, neast, neast, south, passive_tfs_cohort, collaidratio_cohort, passive_tfs_cohort.n, 
                                collaidratio_cohort.n))
  cohort$ACERECODE <- rownames(cohort)
  cohort$YEAR_TFS <- yrs[i] 
  cohortdata[[i]] <- cohort
}

cohortdata8988 <- as.data.frame(cohortdata[[1]])
cohortdata9089 <- as.data.frame(cohortdata[[2]])
cohortdata9190 <- as.data.frame(cohortdata[[3]])
cohortdata9291 <- as.data.frame(cohortdata[[4]])
cohortdata9392 <- as.data.frame(cohortdata[[5]])
cohortdata9493 <- as.data.frame(cohortdata[[6]])
cohortdata9594 <- as.data.frame(cohortdata[[7]])
cohortdata9695 <- as.data.frame(cohortdata[[8]])
cohortdata9796 <- as.data.frame(cohortdata[[9]])
cohortdata9897 <- as.data.frame(cohortdata[[10]])
cohortdata9998 <- as.data.frame(cohortdata[[11]])
cohortdata0099 <- as.data.frame(cohortdata[[12]])
cohortdata0100 <- as.data.frame(cohortdata[[13]])
cohortdata0201 <- as.data.frame(cohortdata[[14]])
cohortdata0302 <- as.data.frame(cohortdata[[15]])
cohortdata0403 <- as.data.frame(cohortdata[[16]])
cohortdata0504 <- as.data.frame(cohortdata[[17]])
cohortdata0605 <- as.data.frame(cohortdata[[18]])
cohortdata0706 <- as.data.frame(cohortdata[[19]])
cohortdata0807 <- as.data.frame(cohortdata[[20]])
cohortdata0908 <- as.data.frame(cohortdata[[21]])

cohortdata <- rbind(cohortdata8988,
                    cohortdata9089,
                    cohortdata9190,
                    cohortdata9291,
                    cohortdata9392,
                    cohortdata9493,
                    cohortdata9594, 
                    cohortdata9695,
                    cohortdata9796,
                    cohortdata9897,
                    cohortdata9998,
                    cohortdata0099,
                    cohortdata0100,
                    cohortdata0201, 
                    cohortdata0302,
                    cohortdata0403,
                    cohortdata0504,
                    cohortdata0605, 
                    cohortdata0706,
                    cohortdata0807,
                    cohortdata0908)

passive.tfs.agg <- lmer(passive_tfs_cohort ~  factor(affcat) + hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                          age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                          largesb + public + college + neast + south + factor(YEAR_TFS) + (1 | ACERECODE) , weights= passive_tfs_cohort.n, data = cohortdata)   

modelvars <- c("passive_tfs_cohort",  "affcat", "hitestscoreper", "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south", "YEAR_TFS", "ACERECODE")

cohortdata_passive <- cohortdata[complete.cases(cohortdata[,modelvars]),]

passive.tfs.agg.p <- summary(passive.tfs.agg)$coefficients["factor(affcat)5",5] 

cohortdata_passive$affcat <- 1
passive.tfs.agg.lis.1 <- mean(predict(passive.tfs.agg, cohortdata_passive, re.form=NULL)) 
cohortdata_passive$affcat <- 5
passive.tfs.agg.lis.5 <- mean(predict(passive.tfs.agg, cohortdata_passive, re.form=NULL)) 
passive.tfs.agg.eff <- passive.tfs.agg.lis.5 - passive.tfs.agg.lis.1

collegeaidratio.agg <- lmer(collaidratio_cohort ~  factor(affcat) + hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                              age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                              largesb + public + college + neast + south + factor(YEAR_TFS) + (1 | ACERECODE) , weights= collaidratio_cohort.n, data = cohortdata)  

modelvars <- c("collaidratio_cohort", "affcat", "hitestscoreper", "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south", "YEAR_TFS", "ACERECODE")

cohortdata_collaidratio <- cohortdata[complete.cases(cohortdata[,modelvars]),]

collegeaidratio.agg.p <- summary(collegeaidratio.agg)$coefficients["factor(affcat)5",5] 

cohortdata_collaidratio$affcat <- 1
collegeaidratio.agg.lis.1 <- mean(predict(collegeaidratio.agg, cohortdata_collaidratio, re.form=NULL)) 
cohortdata_collaidratio$affcat <- 5
collegeaidratio.agg.lis.5 <- mean(predict(collegeaidratio.agg, cohortdata_collaidratio, re.form=NULL)) 
collegeaidratio.agg.eff <- collegeaidratio.agg.lis.5 - collegeaidratio.agg.lis.1

######################
# Results in Table 1 #
######################

emohealth.lis.eff
emohealth.lis.p

emohealth.mis.eff
emohealth.mis.p

emohealth.his.eff
emohealth.his.p

motivationlead.lis.eff
motivationlead.lis.p

motivationlead.mis.eff
motivationlead.mis.p

motivationlead.his.eff
motivationlead.his.p

academcomp.lis.eff
academcomp.lis.p

academcomp.mis.eff
academcomp.mis.p

academcomp.his.eff
academcomp.his.p

soccon.lis.eff
soccon.lis.p

soccon.mis.eff
soccon.mis.p

soccon.his.eff
soccon.his.p

socsatis.lis.eff
socsatis.lis.p

socsatis.mis.eff
socsatis.mis.p

socsatis.his.eff
socsatis.his.p

hpwworking.lis.eff
hpwworking.lis.p

hpwworking.mis.eff
hpwworking.mis.p

hpwworking.his.eff
hpwworking.his.p

collegeaidratio.agg.eff
collegeaidratio.agg.p

passive.tfs.agg.eff
passive.tfs.agg.p

###########
# Table 2 # 
###########

#######################
## Academic Mechanism #
#######################

## academic competence at the individual-level and cohort-level

passive.lis.academcomp_tfs01 <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + factor(affcat)*factor(academcomp_tfs01 ) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                                       evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                                       hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                                       age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                                       largesb + public + college + neast + south + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), data = data.lis)  

voteprez2.lis.academcomp_tfs01  <- glmer(voteprez2 ~ polaffairs_tfs + factor(affcat)*factor(academcomp_tfs01 ) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                                           otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                                           hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                                           socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                                           factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

campaign.lis.academcomp_tfs01  <- glmer(campaign_css ~ campaign_tfs + factor(affcat)*factor(academcomp_tfs01 ) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                                          otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                                          hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                                          socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                                          factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

elected.lis.academcomp_tfs01  <- glmer(elected01_gov ~ commlead_tfs + factor(affcat)*factor(academcomp_tfs01 ) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                                         otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                                         hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                                         socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                                         factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

orglead.lis.academcomp_tfs01  <- glmer(orglead01 ~ commlead_tfs + factor(affcat)*factor(academcomp_tfs01 ) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                                         otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                                         hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                                         socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                                         factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

protest.lis.academcomp_tfs01  <-  glmer(protestindex_css ~ protest_tfs + factor(affcat)*factor(academcomp_tfs01 ) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                                          otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                                          hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                                          socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                                          factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

#######################
## Financial Mechanism
######################

#individual (financial) college aid

passive.lis.collaidratio01 <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + factor(affcat)*factor(collaidratio01) + hitestscore + testscore_na + female +
                                     asian + hispanic + black + othrace + jewish + catholic + evangelical + otherornorelig + notenglishfirst + age17orless +
                                     age19 + age20 + socscitfs + humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                     hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                                     age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + makemoneyvimpper +
                                     mostlyfemale + mostlyblack +  largesb + public + college + neast +  south + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), 
                                   data = data.lis)

voting.lis.collaidratio01 <- glmer(voteprez2 ~ polaffairs_tfs + factor(affcat)*factor(collaidratio01) + hitestscore + testscore_na + female +
                                     asian + hispanic + black + othrace + jewish + catholic + evangelical + otherornorelig + notenglishfirst + age17orless +
                                     age19 + age20 + socscitfs + humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                     hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                                     age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + makemoneyvimpper +
                                     mostlyfemale + mostlyblack +  largesb + public + college + neast +  south + factor(YEAR) + 
                                     (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

campaign.lis.collaidratio01 <- glmer(campaign_css ~ campaign_tfs + factor(affcat)*factor(collaidratio01) + hitestscore + testscore_na + female +
                                       asian + hispanic + black + othrace + jewish + catholic + evangelical + otherornorelig + notenglishfirst + age17orless +
                                       age19 + age20 + socscitfs + humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                       hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                                       age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + makemoneyvimpper +
                                       mostlyfemale + mostlyblack +  largesb + public + college + neast +  south + factor(YEAR) + 
                                       (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

protest.lis.collaidratio01 <- glmer(protestindex_css ~ protest_tfs + factor(affcat)*factor(collaidratio01) + hitestscore + testscore_na + female +
                                      asian + hispanic + black + othrace + jewish + catholic + evangelical + otherornorelig + notenglishfirst + age17orless +
                                      age19 + age20 + socscitfs + humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                      hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                                      age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + makemoneyvimpper +
                                      mostlyfemale + mostlyblack +  largesb + public + college + neast +  south + factor(YEAR) + 
                                      (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

elected.lis.collaidratio01 <- glmer(elected01_gov ~ commlead_tfs + factor(affcat)*factor(collaidratio01) + hitestscore + testscore_na + female +
                                      asian + hispanic + black + othrace + jewish + catholic + evangelical + otherornorelig + notenglishfirst + age17orless +
                                      age19 + age20 + socscitfs + humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                      hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                                      age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + makemoneyvimpper +
                                      mostlyfemale + mostlyblack +  largesb + public + college + neast +  south + factor(YEAR) + 
                                      (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

orglead.lis.collaidratio01 <- glmer(orglead01 ~ commlead_tfs + factor(affcat)*factor(collaidratio01) + hitestscore + testscore_na + female +
                                      asian + hispanic + black + othrace + jewish + catholic + evangelical + otherornorelig + notenglishfirst + age17orless +
                                      age19 + age20 + socscitfs + humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                      hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                                      age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + makemoneyvimpper +
                                      mostlyfemale + mostlyblack +  largesb + public + college + neast +  south + factor(YEAR) + 
                                      (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

#individual level financial concern

passive.lis.fincon01 <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + factor(affcat)*factor(fincon01) + hitestscore + testscore_na + female +
                               asian + hispanic + black + othrace + jewish + catholic + evangelical + otherornorelig + notenglishfirst + age17orless +
                               age19 + age20 + socscitfs + humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                               hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                               age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + makemoneyvimpper +
                               mostlyfemale + mostlyblack +  largesb + public + college + neast +  south + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), 
                             data = data.lis)

voting.lis.fincon01 <- glmer(voteprez2 ~ polaffairs_tfs + factor(affcat)*factor(fincon01) + hitestscore + testscore_na + female +
                               asian + hispanic + black + othrace + jewish + catholic + evangelical + otherornorelig + notenglishfirst + age17orless +
                               age19 + age20 + socscitfs + humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                               hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                               age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + makemoneyvimpper +
                               mostlyfemale + mostlyblack +  largesb + public + college + neast +  south + factor(YEAR) + 
                               (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

campaign.lis.fincon01 <- glmer(campaign_css ~ campaign_tfs + factor(affcat)*factor(fincon01) + hitestscore + testscore_na + female +
                                 asian + hispanic + black + othrace + jewish + catholic + evangelical + otherornorelig + notenglishfirst + age17orless +
                                 age19 + age20 + socscitfs + humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                 hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                                 age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + makemoneyvimpper +
                                 mostlyfemale + mostlyblack +  largesb + public + college + neast +  south + factor(YEAR) + 
                                 (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

protest.lis.fincon01 <- glmer(protestindex_css ~ protest_tfs + factor(affcat)*factor(fincon01) + hitestscore + testscore_na + female +
                                asian + hispanic + black + othrace + jewish + catholic + evangelical + otherornorelig + notenglishfirst + age17orless +
                                age19 + age20 + socscitfs + humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                                age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + makemoneyvimpper +
                                mostlyfemale + mostlyblack +  largesb + public + college + neast +  south + factor(YEAR) + 
                                (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

elected.lis.fincon01 <- glmer(elected01_gov ~ commlead_tfs + factor(affcat)*factor(fincon01) + hitestscore + testscore_na + female +
                                asian + hispanic + black + othrace + jewish + catholic + evangelical + otherornorelig + notenglishfirst + age17orless +
                                age19 + age20 + socscitfs + humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                                age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + makemoneyvimpper +
                                mostlyfemale + mostlyblack +  largesb + public + college + neast +  south + factor(YEAR) + 
                                (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

orglead.lis.fincon01 <- glmer(orglead01 ~ commlead_tfs + factor(affcat)*factor(fincon01) + hitestscore + testscore_na + female +
                                asian + hispanic + black + othrace + jewish + catholic + evangelical + otherornorelig + notenglishfirst + age17orless +
                                age19 + age20 + socscitfs + humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                                age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + makemoneyvimpper +
                                mostlyfemale + mostlyblack +  largesb + public + college + neast +  south + factor(YEAR) + 
                                (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

# Aggregate Financial Concern

# Load data with aggregate financial concern

aggaidvars <- read.csv("finconagg.csv")

csscohort <- merge(csscohort, aggaidvars, all.x = T, by = c("ACERECODE"))

data.lis <- csscohort[csscohort$parinc == "Low-Income",]

data.lis <- data.lis[match(c(data.lis$subjid_year), data.lis$subjid_year),]

csscohort$fincon.lis.school01 <- ifelse(csscohort$fincon01.lis.school 
                                          <= quantile(data.lis$fincon01.lis.school, c(.5), na.rm = T), 0, 1) 

data.lis <- csscohort[csscohort$parinc == "Low-Income",]

data.lis <- data.lis[match(c(data.lis$subjid_year), data.lis$subjid_year),]

passive.lis.fincon.lis.school01 <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + factor(affcat)*factor(fincon.lis.school01) + hitestscore + testscore_na + female +
                                          asian + hispanic + black + othrace + jewish + catholic + evangelical + otherornorelig + notenglishfirst + age17orless +
                                          age19 + age20 + socscitfs + humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                          hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                                          age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + makemoneyvimpper +
                                          mostlyfemale + mostlyblack +  largesb + public + college + neast +  south + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), 
                                        data = data.lis)

voting.lis.fincon.lis.school01 <- glmer(voteprez2 ~ polaffairs_tfs + factor(affcat)*factor(fincon.lis.school01) + hitestscore + testscore_na + female +
                                          asian + hispanic + black + othrace + jewish + catholic + evangelical + otherornorelig + notenglishfirst + age17orless +
                                          age19 + age20 + socscitfs + humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                          hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                                          age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + makemoneyvimpper +
                                          mostlyfemale + mostlyblack +  largesb + public + college + neast +  south + factor(YEAR) + 
                                          (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

campaign.lis.fincon.lis.school01 <- glmer(campaign_css ~ campaign_tfs + factor(affcat)*factor(fincon.lis.school01) + hitestscore + testscore_na + female +
                                            asian + hispanic + black + othrace + jewish + catholic + evangelical + otherornorelig + notenglishfirst + age17orless +
                                            age19 + age20 + socscitfs + humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                            hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                                            age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + makemoneyvimpper +
                                            mostlyfemale + mostlyblack +  largesb + public + college + neast +  south + factor(YEAR) + 
                                            (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

protest.lis.fincon.lis.school01 <- glmer(protestindex_css ~ protest_tfs + factor(affcat)*factor(fincon.lis.school01) + hitestscore + testscore_na + female +
                                           asian + hispanic + black + othrace + jewish + catholic + evangelical + otherornorelig + notenglishfirst + age17orless +
                                           age19 + age20 + socscitfs + humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                           hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                                           age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + makemoneyvimpper +
                                           mostlyfemale + mostlyblack +  largesb + public + college + neast +  south + factor(YEAR) + 
                                           (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

elected.lis.fincon.lis.school01 <- glmer(elected01_gov ~ commlead_tfs + factor(affcat)*factor(fincon.lis.school01) + hitestscore + testscore_na + female +
                                           asian + hispanic + black + othrace + jewish + catholic + evangelical + otherornorelig + notenglishfirst + age17orless +
                                           age19 + age20 + socscitfs + humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                           hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                                           age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + makemoneyvimpper +
                                           mostlyfemale + mostlyblack +  largesb + public + college + neast +  south + factor(YEAR) + 
                                           (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

orglead.lis.fincon.lis.school01 <- glmer(orglead01 ~ commlead_tfs + factor(affcat)*factor(fincon.lis.school01) + hitestscore + testscore_na + female +
                                           asian + hispanic + black + othrace + jewish + catholic + evangelical + otherornorelig + notenglishfirst + age17orless +
                                           age19 + age20 + socscitfs + humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                           hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                                           age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + makemoneyvimpper +
                                           mostlyfemale + mostlyblack +  largesb + public + college + neast +  south + factor(YEAR) + 
                                           (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

# Dorms and Dining Halls Index 

passive.lis.closedfac <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + factor(affcat)*factor(closedfac) + hitestscore + testscore_na + female +
                                asian + hispanic + black + othrace + jewish + catholic + evangelical + otherornorelig + notenglishfirst + age17orless +
                                age19 + age20 + socscitfs + humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                                age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + makemoneyvimpper +
                                mostlyfemale + mostlyblack +  largesb + public + college + neast +  south + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), 
                              data = data.lis)

voting.lis.closedfac <- glmer(voteprez2 ~ polaffairs_tfs + factor(affcat)*factor(closedfac) + hitestscore + testscore_na + female +
                                asian + hispanic + black + othrace + jewish + catholic + evangelical + otherornorelig + notenglishfirst + age17orless +
                                age19 + age20 + socscitfs + humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                                age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + makemoneyvimpper +
                                mostlyfemale + mostlyblack +  largesb + public + college + neast +  south + factor(YEAR) + 
                                (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

campaign.lis.closedfac <- glmer(campaign_css ~ campaign_tfs + factor(affcat)*factor(closedfac) + hitestscore + testscore_na + female +
                                  asian + hispanic + black + othrace + jewish + catholic + evangelical + otherornorelig + notenglishfirst + age17orless +
                                  age19 + age20 + socscitfs + humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + makemoneyvimpper +
                                  mostlyfemale + mostlyblack +  largesb + public + college + neast +  south + factor(YEAR) + 
                                  (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

protest.lis.closedfac <- glmer(protestindex_css ~ protest_tfs + factor(affcat)*factor(closedfac) + hitestscore + testscore_na + female +
                                 asian + hispanic + black + othrace + jewish + catholic + evangelical + otherornorelig + notenglishfirst + age17orless +
                                 age19 + age20 + socscitfs + humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                 hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                                 age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + makemoneyvimpper +
                                 mostlyfemale + mostlyblack +  largesb + public + college + neast +  south + factor(YEAR) + 
                                 (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

elected.lis.closedfac <- glmer(elected01_gov ~ commlead_tfs + factor(affcat)*factor(closedfac) + hitestscore + testscore_na + female +
                                 asian + hispanic + black + othrace + jewish + catholic + evangelical + otherornorelig + notenglishfirst + age17orless +
                                 age19 + age20 + socscitfs + humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                 hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                                 age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + makemoneyvimpper +
                                 mostlyfemale + mostlyblack +  largesb + public + college + neast +  south + factor(YEAR) + 
                                 (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

orglead.lis.closedfac <- glmer(orglead01 ~ commlead_tfs + factor(affcat)*factor(closedfac) + hitestscore + testscore_na + female +
                                 asian + hispanic + black + othrace + jewish + catholic + evangelical + otherornorelig + notenglishfirst + age17orless +
                                 age19 + age20 + socscitfs + humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                 hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                                 age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + makemoneyvimpper +
                                 mostlyfemale + mostlyblack +  largesb + public + college + neast +  south + factor(YEAR) + 
                                 (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

############################
## Psychological Mechanism #
############################

# individual-level  emotional health

passive.lis.emohealth_tfs01 <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + factor(affcat)*factor(emohealth_tfs01 ) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                                      evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                                      hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                                      age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                                      largesb + public + college + neast + south + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), data = data.lis)  

voteprez2.lis.emohealth_tfs01  <- glmer(voteprez2 ~ polaffairs_tfs + factor(affcat)*factor(emohealth_tfs01 ) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                                          otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                                          hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                                          socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                                          factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

campaign.lis.emohealth_tfs01  <- glmer(campaign_css ~ campaign_tfs + factor(affcat)*factor(emohealth_tfs01 ) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                                         otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                                         hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                                         socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                                         factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

elected.lis.emohealth_tfs01  <- glmer(elected01_gov ~ commlead_tfs + factor(affcat)*factor(emohealth_tfs01 ) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                                        otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                                        hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                                        socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                                        factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

orglead.lis.emohealth_tfs01  <- glmer(orglead01 ~ commlead_tfs + factor(affcat)*factor(emohealth_tfs01 ) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                                        otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                                        hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                                        socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                                        factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

protest.lis.emohealth_tfs01  <-  glmer(protestindex_css ~ protest_tfs + factor(affcat)*factor(emohealth_tfs01 ) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                                         otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                                         hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                                         socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                                         factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

# individual-level motivation to lead

passive.lis.motivationlead_tfs01 <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + factor(affcat)*factor(motivationlead_tfs01 ) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                                           evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                                           hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                                           age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                                           largesb + public + college + neast + south + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), data = data.lis)  

voteprez2.lis.motivationlead_tfs01  <- glmer(voteprez2 ~ polaffairs_tfs + factor(affcat)*factor(motivationlead_tfs01 ) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                                               otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                                               hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                                               socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                                               factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

campaign.lis.motivationlead_tfs01  <- glmer(campaign_css ~ campaign_tfs + factor(affcat)*factor(motivationlead_tfs01 ) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                                              otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                                              hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                                              socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                                              factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

elected.lis.motivationlead_tfs01  <- glmer(elected01_gov ~ commlead_tfs + factor(affcat)*factor(motivationlead_tfs01 ) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                                             otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                                             hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                                             socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                                             factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

orglead.lis.motivationlead_tfs01  <- glmer(orglead01 ~ commlead_tfs + factor(affcat)*factor(motivationlead_tfs01 ) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                                             otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                                             hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                                             socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                                             factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

protest.lis.motivationlead_tfs01  <-  glmer(protestindex_css ~ protest_tfs + factor(affcat)*factor(motivationlead_tfs01 ) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                                              otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                                              hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                                              socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                                              factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

#######################
## Social Mechanism
######################

# individual-level and aggregate social confidence

passive.lis.soccon_tfs01 <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + factor(affcat)*factor(soccon_tfs01 ) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                                   evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                                   hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                                   age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                                   largesb + public + college + neast + south + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), data = data.lis)  

passive.lis.soccon_tfs_cohort01 <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + factor(affcat)*factor(soccon_tfs_cohort01 ) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + 
                                          catholic + evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                                          hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                                          age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                                          largesb + public + college + neast + south + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), data = data.lis)  

voteprez2.lis.soccon_tfs01  <- glmer(voteprez2 ~ polaffairs_tfs + factor(affcat)*factor(soccon_tfs01 ) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                                       otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                                       hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                                       socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                                       factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

voteprez2.lis.soccon_tfs_cohort01 <- glmer(voteprez2 ~ polaffairs_tfs + factor(affcat)*factor(soccon_tfs_cohort01 ) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                                             otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                                             hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                                             socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                                             factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

campagn.lis.soccon_tfs01  <- glmer(campaign_css ~ campaign_tfs + factor(affcat)*factor(soccon_tfs01 ) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                                      otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                                      hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                                      socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                                      factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

campaign.lis.soccon_tfs_cohort01 <- glmer(campaign_css ~ campaign_tfs + factor(affcat)*factor(soccon_tfs_cohort01 ) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                                            otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                                            hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                                            socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                                            factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

elected.lis.soccon_tfs01  <- glmer(elected01_gov ~ commlead_tfs + factor(affcat)*factor(soccon_tfs01 ) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                                     otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                                     hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                                     socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                                     factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

elected.lis.soccon_tfs_cohort01 <- glmer(elected01_gov ~ commlead_tfs + factor(affcat)*factor(soccon_tfs_cohort01 ) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                                           otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                                           hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                                           socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                                           factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

orglead.lis.soccon_tfs01  <- glmer(orglead01 ~ commlead_tfs + factor(affcat)*factor(soccon_tfs01 ) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                                     otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                                     hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                                     socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                                     factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

orglead.lis.soccon_tfs_cohort01 <- glmer(orglead01 ~ commlead_tfs + factor(affcat)*factor(soccon_tfs_cohort01 ) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                                           otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                                           hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                                           socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                                           factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

protest.lis.soccon_tfs01  <-  glmer(protestindex_css ~ protest_tfs + factor(affcat)*factor(soccon_tfs01 ) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                                      otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                                      hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                                      socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                                      factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

protest.lis.soccon_tfs_cohort01 <-  glmer(protestindex_css ~ protest_tfs + factor(affcat)*factor(soccon_tfs_cohort01 ) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                                            otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                                            hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                                            socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                                            factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

# Effects for Table 2

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "passive_index_tfs_avg", 
               "passive_index_css_avg", "academcomp_tfs01")

data.lis <- data.lis[complete.cases(data.lis[,modelvars]),]
data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$academcomp_tfs01 <- 0 
aff1.cat0 <- mean(predict(passive.lis.academcomp_tfs01, fixed, type = "response", allow.new.levels=TRUE), na.rm = T)
aff1.cat0

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$academcomp_tfs01 <- 0 
aff5.cat0 <- mean(predict(passive.lis.academcomp_tfs01, fixed, type = "response", allow.new.levels=TRUE), na.rm = T)
aff5.cat0

# Take difference

passive.academcomp_tfs01.cat0.diff <- aff5.cat0 - aff1.cat0 
passive.academcomp_tfs01.cat0.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$academcomp_tfs01 <- 1 
aff1.cat1 <- mean(predict(passive.lis.academcomp_tfs01, fixed, type = "response", allow.new.levels=TRUE), na.rm = T)
aff1.cat1

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$academcomp_tfs01 <- 1 
aff5.cat1 <- mean(predict(passive.lis.academcomp_tfs01, fixed, type = "response", allow.new.levels=TRUE), na.rm = T)
aff5.cat1

# Take difference

passive.academcomp_tfs01.cat1.diff <- aff5.cat1 - aff1.cat1 
passive.academcomp_tfs01.cat1.diff

###########
# Voting #
###########

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "academcomp_tfs01", 
               "voteprez2", "polaffairs_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$academcomp_tfs01 <- 0 
aff1.cat0 <- mean(predict(voteprez2.lis.academcomp_tfs01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$academcomp_tfs01 <- 0 
aff5.cat0 <- mean(predict(voteprez2.lis.academcomp_tfs01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

voting.academcomp_tfs01.cat0.diff <- aff5.cat0 - aff1.cat0 
voting.academcomp_tfs01.cat0.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$academcomp_tfs01 <- 1 
aff1.cat1 <- mean(predict(voteprez2.lis.academcomp_tfs01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$academcomp_tfs01 <- 1 
aff5.cat1 <- mean(predict(voteprez2.lis.academcomp_tfs01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

voting.academcomp_tfs01.cat1.diff <- aff5.cat1 - aff1.cat1 
voting.academcomp_tfs01.cat1.diff

###############
# Campaigning #
###############

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "academcomp_tfs01", 
               "campaign_css", "campaign_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$academcomp_tfs01 <- 0 
aff1.cat0 <- mean(predict(campaign.lis.academcomp_tfs01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$academcomp_tfs01 <- 0 
aff5.cat0 <- mean(predict(campaign.lis.academcomp_tfs01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

campaign.academcomp_tfs01.cat0.diff <- aff5.cat0 - aff1.cat0 
campaign.academcomp_tfs01.cat0.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$academcomp_tfs01 <- 1 
aff1.cat1 <- mean(predict(campaign.lis.academcomp_tfs01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$academcomp_tfs01 <- 1 
aff5.cat1 <- mean(predict(campaign.lis.academcomp_tfs01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

campaign.academcomp_tfs01.cat1.diff <- aff5.cat1 - aff1.cat1 
campaign.academcomp_tfs01.cat1.diff

###########
# Protest #
########### 

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "academcomp_tfs01", 
               "protestindex_css", "protest_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$academcomp_tfs01 <- 0 
aff1.cat0 <- mean(predict(protest.lis.academcomp_tfs01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$academcomp_tfs01 <- 0 
aff5.cat0 <- mean(predict(protest.lis.academcomp_tfs01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

protest.academcomp_tfs01.cat0.diff <- aff5.cat0 - aff1.cat0
protest.academcomp_tfs01.cat0.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$academcomp_tfs01 <- 1 
aff1.cat1 <- mean(predict(protest.lis.academcomp_tfs01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$academcomp_tfs01 <- 1 
aff5.cat1 <- mean(predict(protest.lis.academcomp_tfs01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

protest.academcomp_tfs01.cat1.diff <- aff5.cat1 - aff1.cat1 
protest.academcomp_tfs01.cat1.diff

#############################
# Elected to Student Office #
#############################

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "academcomp_tfs01", 
               "elected01_gov", "commlead_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$academcomp_tfs01 <- 0 
aff1.cat0 <- mean(predict(elected.lis.academcomp_tfs01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$academcomp_tfs01 <- 0 
aff5.cat0 <- mean(predict(elected.lis.academcomp_tfs01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

elected.academcomp_tfs01.cat0.diff <- aff5.cat0 - aff1.cat0 
elected.academcomp_tfs01.cat0.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$academcomp_tfs01 <- 1 
aff1.cat1 <- mean(predict(elected.lis.academcomp_tfs01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$academcomp_tfs01 <- 1 
aff5.cat1 <- mean(predict(elected.lis.academcomp_tfs01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

elected.academcomp_tfs01.cat1.diff <- aff5.cat1 - aff1.cat1 
elected.academcomp_tfs01.cat1.diff

#############################
# Lead Student Organization # 
#############################

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "academcomp_tfs01", 
               "orglead01", "commlead_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$academcomp_tfs01 <- 0 
aff1.cat0 <- mean(predict(orglead.lis.academcomp_tfs01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$academcomp_tfs01 <- 0 
aff5.cat0 <- mean(predict(orglead.lis.academcomp_tfs01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

orglead.academcomp_tfs01.cat0.diff <- aff5.cat0 - aff1.cat0
orglead.academcomp_tfs01.cat0.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$academcomp_tfs01 <- 1 
aff1.cat1 <- mean(predict(orglead.lis.academcomp_tfs01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$academcomp_tfs01 <- 1 
aff5.cat1 <- mean(predict(orglead.lis.academcomp_tfs01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

orglead.academcomp_tfs01.cat1.diff <- aff5.cat1 - aff1.cat1
orglead.academcomp_tfs01.cat1.diff

# Emotional health

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "passive_index_tfs_avg", 
               "passive_index_css_avg", "emohealth_tfs01")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$emohealth_tfs01 <- 0 
aff1.cat0 <- mean(predict(passive.lis.emohealth_tfs01, fixed, type = "response", allow.new.levels=TRUE), na.rm = T)

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$emohealth_tfs01 <- 0 
aff5.cat0 <- mean(predict(passive.lis.emohealth_tfs01, fixed, type = "response", allow.new.levels=TRUE), na.rm = T)

# Take difference

passive.emohealth_tfs.cat0.diff <- aff5.cat0 - aff1.cat0 
passive.emohealth_tfs.cat0.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$emohealth_tfs01 <- 1 
aff1.cat1 <- mean(predict(passive.lis.emohealth_tfs01, fixed, type = "response", allow.new.levels=TRUE), na.rm = T)

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$emohealth_tfs01 <- 1 
aff5.cat1 <- mean(predict(passive.lis.emohealth_tfs01, fixed, type = "response", allow.new.levels=TRUE), na.rm = T)

# Take difference

passive.emohealth_tfs.cat1.diff <- aff5.cat1 - aff1.cat1 
passive.emohealth_tfs.cat1.diff

###########
# Voting #
###########

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "emohealth_tfs01", 
               "voteprez2", "polaffairs_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$emohealth_tfs01 <- 0 
aff1.cat0 <- mean(predict(voteprez2.lis.emohealth_tfs01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$emohealth_tfs01 <- 0 
aff5.cat0 <- mean(predict(voteprez2.lis.emohealth_tfs01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

voting.emohealth_tfs.cat0.diff <- aff5.cat0 - aff1.cat0 
voting.emohealth_tfs.cat0.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$emohealth_tfs01 <- 1 
aff1.cat1 <- mean(predict(voteprez2.lis.emohealth_tfs01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$emohealth_tfs01 <- 1 
aff5.cat1 <- mean(predict(voteprez2.lis.emohealth_tfs01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

voting.emohealth_tfs.cat1.diff <- aff5.cat1 - aff1.cat1 
voting.emohealth_tfs.cat1.diff

###############
# Campaigning #
###############

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "emohealth_tfs01", 
               "campaign_css", "campaign_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$emohealth_tfs01 <- 0 
aff1.cat0 <- mean(predict(campaign.lis.emohealth_tfs01, fixed, type = "response", allow.new.levels=TRUE))


fixed <- data.lis.temp
fixed$affcat <- 5
fixed$emohealth_tfs01 <- 0 
aff5.cat0 <- mean(predict(campaign.lis.emohealth_tfs01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

campaign.emohealth_tfs.cat0.diff <- aff5.cat0 - aff1.cat0 
campaign.emohealth_tfs.cat0.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$emohealth_tfs01 <- 1 
aff1.cat1 <- mean(predict(campaign.lis.emohealth_tfs01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$emohealth_tfs01 <- 1 
aff5.cat1 <- mean(predict(campaign.lis.emohealth_tfs01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

campaign.emohealth_tfs.cat1.diff <- aff5.cat1 - aff1.cat1 
campaign.emohealth_tfs.cat1.diff

###########
# Protest #
########### 

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "emohealth_tfs01", 
               "protestindex_css", "protest_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$emohealth_tfs01 <- 0 
aff1.cat0 <- mean(predict(protest.lis.emohealth_tfs01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$emohealth_tfs01 <- 0 
aff5.cat0 <- mean(predict(protest.lis.emohealth_tfs01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

protest.emohealth_tfs.cat0.diff <- aff5.cat0 - aff1.cat0
protest.emohealth_tfs.cat0.diff 

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$emohealth_tfs01 <- 1 
aff1.cat1 <- mean(predict(protest.lis.emohealth_tfs01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$emohealth_tfs01 <- 1 
aff5.cat1 <- mean(predict(protest.lis.emohealth_tfs01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

protest.emohealth_tfs.cat1.diff <- aff5.cat1 - aff1.cat1 
protest.emohealth_tfs.cat1.diff

#############################
# Elected to Student Office #
#############################

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "emohealth_tfs01", 
               "elected01_gov", "commlead_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$emohealth_tfs01 <- 0 
aff1.cat0 <- mean(predict(elected.lis.emohealth_tfs01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$emohealth_tfs01 <- 0 
aff5.cat0 <- mean(predict(elected.lis.emohealth_tfs01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

elected.emohealth_tfs.cat0.diff <- aff5.cat0 - aff1.cat0 
elected.emohealth_tfs.cat0.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$emohealth_tfs01 <- 1 
aff1.cat1 <- mean(predict(elected.lis.emohealth_tfs01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$emohealth_tfs01 <- 1 
aff5.cat1 <- mean(predict(elected.lis.emohealth_tfs01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

elected.emohealth_tfs.cat1.diff <- aff5.cat1 - aff1.cat1 
elected.emohealth_tfs.cat1.diff 

#############################
# Lead Student Organization # 
#############################

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "emohealth_tfs01", 
               "orglead01", "commlead_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$emohealth_tfs01 <- 0 
aff1.cat0 <- mean(predict(orglead.lis.emohealth_tfs01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$emohealth_tfs01 <- 0 
aff5.cat0 <- mean(predict(orglead.lis.emohealth_tfs01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

orglead.emohealth_tfs.cat0.diff <- aff5.cat0 - aff1.cat0
orglead.emohealth_tfs.cat0.diff 

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$emohealth_tfs01 <- 1 
aff1.cat1 <- mean(predict(orglead.lis.emohealth_tfs01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$emohealth_tfs01 <- 1 
aff5.cat1 <- mean(predict(orglead.lis.emohealth_tfs01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

orglead.emohealth_tfs.cat1.diff <- aff5.cat1 - aff1.cat1
orglead.emohealth_tfs.cat1.diff

# Social confidence

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "passive_index_tfs", 
               "passive_index_css", "soccon_tfs01")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$soccon_tfs01 <- 0 
aff1.cat0 <- mean(predict(passive.lis.soccon_tfs01, fixed, type = "response", allow.new.levels=TRUE), na.rm = T)

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$soccon_tfs01 <- 0 
aff5.cat0 <- mean(predict(passive.lis.soccon_tfs01, fixed, type = "response", allow.new.levels=TRUE), na.rm = T)

# Take difference

passive.soccon_tfs.cat0.diff <- aff5.cat0 - aff1.cat0 
passive.soccon_tfs.cat0.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$soccon_tfs01 <- 1 
aff1.cat1 <- mean(predict(passive.lis.soccon_tfs01, fixed, type = "response", allow.new.levels=TRUE), na.rm = T)

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$soccon_tfs01 <- 1 
aff5.cat1 <- mean(predict(passive.lis.soccon_tfs01, fixed, type = "response", allow.new.levels=TRUE), na.rm = T)

# Take difference

passive.soccon_tfs.cat1.diff <- aff5.cat1 - aff1.cat1 
passive.soccon_tfs.cat1.diff

###########
# Voting #
###########

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "soccon_tfs01", 
               "voteprez2", "polaffairs_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$soccon_tfs01 <- 0 
aff1.cat0 <- mean(predict(voteprez2.lis.soccon_tfs01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$soccon_tfs01 <- 0 
aff5.cat0 <- mean(predict(voteprez2.lis.soccon_tfs01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

voting.soccon_tfs.cat0.diff <- aff5.cat0 - aff1.cat0 
voting.soccon_tfs.cat0.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$soccon_tfs01 <- 1 
aff1.cat1 <- mean(predict(voteprez2.lis.soccon_tfs01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$soccon_tfs01 <- 1 
aff5.cat1 <- mean(predict(voteprez2.lis.soccon_tfs01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

voting.soccon_tfs.cat1.diff <- aff5.cat1 - aff1.cat1 
voting.soccon_tfs.cat1.diff

###############
# Campaigning #
###############

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "soccon_tfs01", 
               "campaign_css", "campaign_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$soccon_tfs01 <- 0 
aff1.cat0 <- mean(predict(campaign.lis.soccon_tfs01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$soccon_tfs01 <- 0 
aff5.cat0 <- mean(predict(campaign.lis.soccon_tfs01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

campaign.soccon_tfs.cat0.diff <- aff5.cat0 - aff1.cat0 
campaign.soccon_tfs.cat0.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$soccon_tfs01 <- 1 
aff1.cat1 <- mean(predict(campaign.lis.soccon_tfs01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$soccon_tfs01 <- 1 
aff5.cat1 <- mean(predict(campaign.lis.soccon_tfs01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

campaign.soccon_tfs.cat1.diff <- aff5.cat1 - aff1.cat1 
campaign.soccon_tfs.cat1.diff

###########
# Protest #
########### 

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "soccon_tfs01", 
               "protestindex_css", "protest_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$soccon_tfs01 <- 0 
aff1.cat0 <- mean(predict(protest.lis.soccon_tfs01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$soccon_tfs01 <- 0 
aff5.cat0 <- mean(predict(protest.lis.soccon_tfs01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

protest.soccon_tfs.cat0.diff <- aff5.cat0 - aff1.cat0
protest.soccon_tfs.cat0.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$soccon_tfs01 <- 1 
aff1.cat1 <- mean(predict(protest.lis.soccon_tfs01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$soccon_tfs01 <- 1 
aff5.cat1 <- mean(predict(protest.lis.soccon_tfs01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

protest.soccon_tfs.cat1.diff <- aff5.cat1 - aff1.cat1 
protest.soccon_tfs.cat1.diff 

#############################
# Elected to Student Office #
#############################

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "soccon_tfs01", 
               "elected01_gov", "commlead_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$soccon_tfs01 <- 0 
aff1.cat0 <- mean(predict(elected.lis.soccon_tfs01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$soccon_tfs01 <- 0 
aff5.cat0 <- mean(predict(elected.lis.soccon_tfs01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

elected.soccon_tfs.cat0.diff <- aff5.cat0 - aff1.cat0 
elected.soccon_tfs.cat0.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$soccon_tfs01 <- 1 
aff1.cat1 <- mean(predict(elected.lis.soccon_tfs01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$soccon_tfs01 <- 1 
aff5.cat1 <- mean(predict(elected.lis.soccon_tfs01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

elected.soccon_tfs.cat1.diff <- aff5.cat1 - aff1.cat1 
elected.soccon_tfs.cat1.diff

#############################
# Lead Student Organization # 
#############################

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "soccon_tfs01", 
               "orglead01", "commlead_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$soccon_tfs01 <- 0 
aff1.cat0 <- mean(predict(orglead.lis.soccon_tfs01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$soccon_tfs01 <- 0 
aff5.cat0 <- mean(predict(orglead.lis.soccon_tfs01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

orglead.soccon_tfs.cat0.diff <- aff5.cat0 - aff1.cat0
orglead.soccon_tfs.cat0.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$soccon_tfs01 <- 1 
aff1.cat1 <- mean(predict(orglead.lis.soccon_tfs01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$soccon_tfs01 <- 1 
aff5.cat1 <- mean(predict(orglead.lis.soccon_tfs01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

orglead.soccon_tfs.cat1.diff <- aff5.cat1 - aff1.cat1
orglead.soccon_tfs.cat1.diff

#now aggregate social self ocnfidence

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "passive_index_tfs", 
               "passive_index_css", "soccon_tfs_cohort01")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$soccon_tfs_cohort01 <- 0 
aff1.cat0 <- mean(predict(passive.lis.soccon_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE), na.rm = T)

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$soccon_tfs_cohort01 <- 0 
aff5.cat0 <- mean(predict(passive.lis.soccon_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE), na.rm = T)

# Take difference

passive.soccon_tfs.cat0.agg.diff <- aff5.cat0 - aff1.cat0 
passive.soccon_tfs.cat0.agg.diff 

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$soccon_tfs_cohort01 <- 1 
aff1.cat1 <- mean(predict(passive.lis.soccon_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE), na.rm = T)

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$soccon_tfs_cohort01 <- 1 
aff5.cat1 <- mean(predict(passive.lis.soccon_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE), na.rm = T)

# Take difference

passive.soccon_tfs.cat1.agg.diff <- aff5.cat1 - aff1.cat1 
passive.soccon_tfs.cat1.agg.diff

###########
# Voting #
###########

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "soccon_tfs_cohort01", 
               "voteprez2", "polaffairs_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]


fixed <- data.lis.temp
fixed$affcat <- 1
fixed$soccon_tfs_cohort01 <- 0 
aff1.cat0 <- mean(predict(voteprez2.lis.soccon_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$soccon_tfs_cohort01 <- 0 
aff5.cat0 <- mean(predict(voteprez2.lis.soccon_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

voting.soccon_tfs.cat0.agg.diff <- aff5.cat0 - aff1.cat0 
voting.soccon_tfs.cat0.agg.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$soccon_tfs_cohort01 <- 1 
aff1.cat1 <- mean(predict(voteprez2.lis.soccon_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$soccon_tfs_cohort01 <- 1 
aff5.cat1 <- mean(predict(voteprez2.lis.soccon_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

voting.soccon_tfs.cat1.agg.diff <- aff5.cat1 - aff1.cat1 
voting.soccon_tfs.cat1.agg.diff

###############
# Campaigning #
###############

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "soccon_tfs_cohort01", 
               "campaign_css", "campaign_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$soccon_tfs_cohort01 <- 0 
aff1.cat0 <- mean(predict(campaign.lis.soccon_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$soccon_tfs_cohort01 <- 0 
aff5.cat0 <- mean(predict(campaign.lis.soccon_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

campaign.soccon_tfs.cat0.agg.diff <- aff5.cat0 - aff1.cat0 
campaign.soccon_tfs.cat0.agg.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$soccon_tfs_cohort01 <- 1 
aff1.cat1 <- mean(predict(campaign.lis.soccon_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$soccon_tfs_cohort01 <- 1 
aff5.cat1 <- mean(predict(campaign.lis.soccon_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

campaign.soccon_tfs.cat1.agg.diff <- aff5.cat1 - aff1.cat1 
campaign.soccon_tfs.cat1.agg.diff

###########
# Protest #
########### 

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "soccon_tfs_cohort01", 
               "protestindex_css", "protest_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$soccon_tfs_cohort01 <- 0 
aff1.cat0 <- mean(predict(protest.lis.soccon_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))


fixed <- data.lis.temp
fixed$affcat <- 5
fixed$soccon_tfs_cohort01 <- 0 
aff5.cat0 <- mean(predict(protest.lis.soccon_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

protest.soccon_tfs.cat0.agg.diff <- aff5.cat0 - aff1.cat0
protest.soccon_tfs.cat0.agg.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$soccon_tfs_cohort01 <- 1 
aff1.cat1 <- mean(predict(protest.lis.soccon_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$soccon_tfs_cohort01 <- 1 
aff5.cat1 <- mean(predict(protest.lis.soccon_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

protest.soccon_tfs.cat1.agg.diff <- aff5.cat1 - aff1.cat1 
protest.soccon_tfs.cat1.agg.diff

#############################
# Elected to Student Office #
############################

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "soccon_tfs_cohort01", 
               "elected01_gov", "commlead_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$soccon_tfs_cohort01 <- 0 
aff1.cat0 <- mean(predict(elected.lis.soccon_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$soccon_tfs_cohort01 <- 0 
aff5.cat0 <- mean(predict(elected.lis.soccon_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

elected.soccon_tfs.cat0.agg.diff <- aff5.cat0 - aff1.cat0 
elected.soccon_tfs.cat0.agg.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$soccon_tfs_cohort01 <- 1 
aff1.cat1 <- mean(predict(elected.lis.soccon_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$soccon_tfs_cohort01 <- 1 
aff5.cat1 <- mean(predict(elected.lis.soccon_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

elected.soccon_tfs.cat1.agg.diff <- aff5.cat1 - aff1.cat1 
elected.soccon_tfs.cat1.agg.diff

#############################
# Lead Student Organization # 
#############################

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "soccon_tfs_cohort01", 
               "orglead01", "commlead_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$soccon_tfs_cohort01 <- 0 
aff1.cat0 <- mean(predict(orglead.lis.soccon_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$soccon_tfs_cohort01 <- 0 
aff5.cat0 <- mean(predict(orglead.lis.soccon_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

orglead.soccon_tfs.cat0.agg.diff <- aff5.cat0 - aff1.cat0
orglead.soccon_tfs.cat0.agg.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$soccon_tfs_cohort01 <- 1 
aff1.cat1 <- mean(predict(orglead.lis.soccon_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$soccon_tfs_cohort01 <- 1 
aff5.cat1 <- mean(predict(orglead.lis.soccon_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

orglead.soccon_tfs.cat1.agg.diff <- aff5.cat1 - aff1.cat1
orglead.soccon_tfs.cat1.agg.diff


###motivation to lead

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "passive_index_tfs_avg", 
               "passive_index_css_avg", "motivationlead_tfs01")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$motivationlead_tfs01 <- 0 
aff1.cat0 <- mean(predict(passive.lis.motivationlead_tfs01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$motivationlead_tfs01 <- 0 
aff5.cat0 <- mean(predict(passive.lis.motivationlead_tfs01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

passive.motivationlead_tfs.cat0.diff <- aff5.cat0 - aff1.cat0 
passive.motivationlead_tfs.cat0.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$motivationlead_tfs01 <- 1 
aff1.cat1 <- mean(predict(passive.lis.motivationlead_tfs01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$motivationlead_tfs01 <- 1 
aff5.cat1 <- mean(predict(passive.lis.motivationlead_tfs01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

passive.motivationlead_tfs.cat1.diff <- aff5.cat1 - aff1.cat1 
passive.motivationlead_tfs.cat1.diff

###########
# Voting #
###########

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "motivationlead_tfs01", 
               "voteprez2", "polaffairs_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$motivationlead_tfs01 <- 0 
aff1.cat0 <- mean(predict(voteprez2.lis.motivationlead_tfs01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$motivationlead_tfs01 <- 0 
aff5.cat0 <- mean(predict(voteprez2.lis.motivationlead_tfs01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

voting.motivationlead_tfs.cat0.diff <- aff5.cat0 - aff1.cat0 
voting.motivationlead_tfs.cat0.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$motivationlead_tfs01 <- 1 
aff1.cat1 <- mean(predict(voteprez2.lis.motivationlead_tfs01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$motivationlead_tfs01 <- 1 
aff5.cat1 <- mean(predict(voteprez2.lis.motivationlead_tfs01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

voting.motivationlead_tfs.cat1.diff <- aff5.cat1 - aff1.cat1 
voting.motivationlead_tfs.cat1.diff

###############
# Campaigning #
###############

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "motivationlead_tfs01", 
               "campaign_css", "campaign_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]


fixed <- data.lis.temp
fixed$affcat <- 1
fixed$motivationlead_tfs01 <- 0 
aff1.cat0 <- mean(predict(campaign.lis.motivationlead_tfs01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$motivationlead_tfs01 <- 0 
aff5.cat0 <- mean(predict(campaign.lis.motivationlead_tfs01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

campaign.motivationlead_tfs.cat0.diff <- aff5.cat0 - aff1.cat0 
campaign.motivationlead_tfs.cat0.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$motivationlead_tfs01 <- 1 
aff1.cat1 <- mean(predict(campaign.lis.motivationlead_tfs01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$motivationlead_tfs01 <- 1 
aff5.cat1 <- mean(predict(campaign.lis.motivationlead_tfs01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

campaign.motivationlead_tfs.cat1.diff <- aff5.cat1 - aff1.cat1 
campaign.motivationlead_tfs.cat1.diff

###########
# Protest #
########### 

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "motivationlead_tfs01", 
               "protestindex_css", "protest_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$motivationlead_tfs01 <- 0 
aff1.cat0 <- mean(predict(protest.lis.motivationlead_tfs01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$motivationlead_tfs01 <- 0 
aff5.cat0 <- mean(predict(protest.lis.motivationlead_tfs01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

protest.motivationlead_tfs.cat0.diff <- aff5.cat0 - aff1.cat0
protest.motivationlead_tfs.cat0.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$motivationlead_tfs01 <- 1 
aff1.cat1 <- mean(predict(protest.lis.motivationlead_tfs01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$motivationlead_tfs01 <- 1 
aff5.cat1 <- mean(predict(protest.lis.motivationlead_tfs01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

protest.motivationlead_tfs.cat1.diff <- aff5.cat1 - aff1.cat1 
protest.motivationlead_tfs.cat1.diff

#############################
# Elected to Student Office #
#############################

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "motivationlead_tfs01", 
               "elected01_gov", "commlead_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$motivationlead_tfs01 <- 0 
aff1.cat0 <- mean(predict(elected.lis.motivationlead_tfs01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$motivationlead_tfs01 <- 0 
aff5.cat0 <- mean(predict(elected.lis.motivationlead_tfs01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

elected.motivationlead_tfs.cat0.diff <- aff5.cat0 - aff1.cat0 
elected.motivationlead_tfs.cat0.diff 

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$motivationlead_tfs01 <- 1 
aff1.cat1 <- mean(predict(elected.lis.motivationlead_tfs01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$motivationlead_tfs01 <- 1 
aff5.cat1 <- mean(predict(elected.lis.motivationlead_tfs01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

elected.motivationlead_tfs.cat1.diff <- aff5.cat1 - aff1.cat1 
elected.motivationlead_tfs.cat1.diff

# Individual College financial Aid  ratio#

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "collaidratio01", 
               "passive_index_css_avg", "passive_index_tfs_avg")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$collaidratio01 <- 0 
aff1.cat0 <- mean(predict(passive.lis.collaidratio01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$collaidratio01 <- 0 
aff5.cat0 <- mean(predict(passive.lis.collaidratio01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

passive.collaidratio01.cat0.diff <- aff5.cat0 - aff1.cat0 
passive.collaidratio01.cat0.diff 

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$collaidratio01 <- 1 
aff1.cat1 <- mean(predict(passive.lis.collaidratio01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$collaidratio01 <- 1 
aff5.cat1 <- mean(predict(passive.lis.collaidratio01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

passive.collaidratio01.cat1.diff <- aff5.cat1 - aff1.cat1 
passive.collaidratio01.cat1.diff

###########
# Voting #
###########

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "collaidratio01", 
               "voteprez2", "polaffairs_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$collaidratio01 <- 0 
aff1.cat0 <- mean(predict(voting.lis.collaidratio01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$collaidratio01 <- 0 
aff5.cat0 <- mean(predict(voting.lis.collaidratio01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

voting.collaidratio01.cat0.diff <- aff5.cat0 - aff1.cat0 
voting.collaidratio01.cat0.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$collaidratio01 <- 1 
aff1.cat1 <- mean(predict(voting.lis.collaidratio01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$collaidratio01 <- 1 
aff5.cat1 <- mean(predict(voting.lis.collaidratio01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

voting.collaidratio01.cat1.diff <- aff5.cat1 - aff1.cat1 
voting.collaidratio01.cat1.diff

###############
# Campaigning #
###############

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "collaidratio01", 
               "campaign_css", "campaign_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$collaidratio01 <- 0 
aff1.cat0 <- mean(predict(campaign.lis.collaidratio01, fixed, type = "response", allow.new.levels=TRUE))


fixed <- data.lis.temp
fixed$affcat <- 5
fixed$collaidratio01 <- 0 
aff5.cat0 <- mean(predict(campaign.lis.collaidratio01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

campaign.collaidratio01.cat0.diff <- aff5.cat0 - aff1.cat0 
campaign.collaidratio01.cat0.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$collaidratio01 <- 1 
aff1.cat1 <- mean(predict(campaign.lis.collaidratio01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$collaidratio01 <- 1 
aff5.cat1 <- mean(predict(campaign.lis.collaidratio01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

campaign.collaidratio01.cat1.diff <- aff5.cat1 - aff1.cat1
campaign.collaidratio01.cat1.diff
###########
# Protest #
########### 

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "collaidratio01", 
               "protestindex_css", "protest_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$collaidratio01 <- 0 
aff1.cat0 <- mean(predict(protest.lis.collaidratio01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$collaidratio01 <- 0 
aff5.cat0 <- mean(predict(protest.lis.collaidratio01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

protest.collaidratio01.cat0.diff <- aff5.cat0 - aff1.cat0
protest.collaidratio01.cat0.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$collaidratio01 <- 1 
aff1.cat1 <- mean(predict(protest.lis.collaidratio01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$collaidratio01 <- 1 
aff5.cat1 <- mean(predict(protest.lis.collaidratio01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

protest.collaidratio01.cat1.diff <- aff5.cat1 - aff1.cat1 
protest.collaidratio01.cat1.diff
#############################
# Elected to Student Office #
#############################

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "collaidratio01", 
               "elected01_gov", "commlead_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$collaidratio01 <- 0 
aff1.cat0 <- mean(predict(elected.lis.collaidratio01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$collaidratio01 <- 0 
aff5.cat0 <- mean(predict(elected.lis.collaidratio01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

elected.collaidratio01.cat0.diff <- aff5.cat0 - aff1.cat0 
elected.collaidratio01.cat0.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$collaidratio01 <- 1 
aff1.cat1 <- mean(predict(elected.lis.collaidratio01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$collaidratio01 <- 1 
aff5.cat1 <- mean(predict(elected.lis.collaidratio01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

elected.collaidratio01.cat1.diff <- aff5.cat1 - aff1.cat1 
elected.collaidratio01.cat1.diff

#############################
# Lead Student Organization # 
#############################

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "collaidratio01", 
               "orglead01", "commlead_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$collaidratio01 <- 0 
aff1.cat0 <- mean(predict(orglead.lis.collaidratio01, fixed, type = "response", allow.new.levels=TRUE))


fixed <- data.lis.temp
fixed$affcat <- 5
fixed$collaidratio01 <- 0 
aff5.cat0 <- mean(predict(orglead.lis.collaidratio01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

orglead.collaidratio01.cat0.diff <- NA

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$collaidratio01 <- 1 
aff1.cat1 <- mean(predict(orglead.lis.collaidratio01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$collaidratio01 <- 1 
aff5.cat1 <- mean(predict(orglead.lis.collaidratio01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

orglead.collaidratio01.cat1.diff <- NA

# Individual financial concern

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "fincon01", 
               "passive_index_css_avg", "passive_index_tfs_avg")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$fincon01 <- 0 
aff1.cat0 <- mean(predict(passive.lis.fincon01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$fincon01 <- 0 
aff5.cat0 <- mean(predict(passive.lis.fincon01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

passive.fincon01.cat0.diff <- aff5.cat0 - aff1.cat0 
passive.fincon01.cat0.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$fincon01 <- 1 
aff1.cat1 <- mean(predict(passive.lis.fincon01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$fincon01 <- 1 
aff5.cat1 <- mean(predict(passive.lis.fincon01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

passive.fincon01.cat1.diff <- aff5.cat1 - aff1.cat1 
passive.fincon01.cat1.diff 

## Voting

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "fincon01", 
               "voteprez2", "polaffairs_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$fincon01 <- 0 
aff1.cat0 <- mean(predict(voting.lis.fincon01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$fincon01 <- 0 
aff5.cat0 <- mean(predict(voting.lis.fincon01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

voting.fincon01.cat0.diff <- aff5.cat0 - aff1.cat0 
voting.fincon01.cat0.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$fincon01 <- 1 
aff1.cat1 <- mean(predict(voting.lis.fincon01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$fincon01 <- 1 
aff5.cat1 <- mean(predict(voting.lis.fincon01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

voting.fincon01.cat1.diff <- aff5.cat1 - aff1.cat1 
voting.fincon01.cat1.diff

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "fincon01", 
               "campaign_css", "campaign_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$fincon01 <- 0 
aff1.cat0 <- mean(predict(campaign.lis.fincon01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$fincon01 <- 0 
aff5.cat0 <- mean(predict(campaign.lis.fincon01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

campaign.fincon01.cat0.diff <- aff5.cat0 - aff1.cat0 
campaign.fincon01.cat0.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$fincon01 <- 1 
aff1.cat1 <- mean(predict(campaign.lis.fincon01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$fincon01 <- 1 
aff5.cat1 <- mean(predict(campaign.lis.fincon01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

campaign.fincon01.cat1.diff <- aff5.cat1 - aff1.cat1 
campaign.fincon01.cat1.diff

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "fincon01", 
               "protestindex_css", "protest_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$fincon01 <- 0 
aff1.cat0 <- mean(predict(protest.lis.fincon01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$fincon01 <- 0 
aff5.cat0 <- mean(predict(protest.lis.fincon01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

protest.fincon01.cat0.diff <- aff5.cat0 - aff1.cat0
protest.fincon01.cat0.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$fincon01 <- 1 
aff1.cat1 <- mean(predict(protest.lis.fincon01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$fincon01 <- 1 
aff5.cat1 <- mean(predict(protest.lis.fincon01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

protest.fincon01.cat1.diff <- aff5.cat1 - aff1.cat1 
protest.fincon01.cat1.diff

#############################
# Elected to Student Office #
#############################

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "fincon01", 
               "elected01_gov", "commlead_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$fincon01 <- 0 
aff1.cat0 <- mean(predict(elected.lis.fincon01, fixed, type = "response", allow.new.levels=TRUE))


fixed <- data.lis.temp
fixed$affcat <- 5
fixed$fincon01 <- 0 
aff5.cat0 <- mean(predict(elected.lis.fincon01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

elected.fincon01.cat0.diff <- aff5.cat0 - aff1.cat0 
elected.fincon01.cat0.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$fincon01 <- 1 
aff1.cat1 <- mean(predict(elected.lis.fincon01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$fincon01 <- 1 
aff5.cat1 <- mean(predict(elected.lis.fincon01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

elected.fincon01.cat1.diff <- aff5.cat1 - aff1.cat1 
elected.fincon01.cat1.diff

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "fincon01", 
               "orglead01", "commlead_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$fincon01 <- 0 
aff1.cat0 <- mean(predict(orglead.lis.fincon01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$fincon01 <- 0 
aff5.cat0 <- mean(predict(orglead.lis.fincon01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

orglead.fincon01.cat0.diff <- aff5.cat0 - aff1.cat0
orglead.fincon01.cat0.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$fincon01 <- 1 
aff1.cat1 <- mean(predict(orglead.lis.fincon01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$fincon01 <- 1 
aff5.cat1 <- mean(predict(orglead.lis.fincon01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

orglead.fincon01.cat1.diff <- aff5.cat1 - aff1.cat1
orglead.fincon01.cat1.diff 

# Aggregate financial concern

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "fincon.lis.school01", 
               "passive_index_css_avg", "passive_index_tfs_avg")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$fincon.lis.school01 <- 0 
aff1.cat0 <- mean(predict(passive.lis.fincon.lis.school01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$fincon.lis.school01 <- 0 
aff5.cat0 <- mean(predict(passive.lis.fincon.lis.school01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

passive.fincon.lis.school01.cat0.diff <- aff5.cat0 - aff1.cat0 
passive.fincon.lis.school01.cat0.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$fincon.lis.school01 <- 1 
aff1.cat1 <- mean(predict(passive.lis.fincon.lis.school01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$fincon.lis.school01 <- 1 
aff5.cat1 <- mean(predict(passive.lis.fincon.lis.school01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

passive.fincon.lis.school01.cat1.diff <- aff5.cat1 - aff1.cat1 
passive.fincon.lis.school01.cat1.diff 

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "fincon.lis.school01", 
               "voteprez2", "polaffairs_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$fincon.lis.school01 <- 0 
aff1.cat0 <- mean(predict(voting.lis.fincon.lis.school01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$fincon.lis.school01 <- 0 
aff5.cat0 <- mean(predict(voting.lis.fincon.lis.school01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

voting.fincon.lis.school01.cat0.diff <- aff5.cat0 - aff1.cat0 
voting.fincon.lis.school01.cat0.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$fincon.lis.school01 <- 1 
aff1.cat1 <- mean(predict(voting.lis.fincon.lis.school01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$fincon.lis.school01 <- 1 
aff5.cat1 <- mean(predict(voting.lis.fincon.lis.school01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

voting.fincon.lis.school01.cat1.diff <- aff5.cat1 - aff1.cat1 
voting.fincon.lis.school01.cat1.diff

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "fincon.lis.school01", 
               "campaign_css", "campaign_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$fincon.lis.school01 <- 0 
aff1.cat0 <- mean(predict(campaign.lis.fincon.lis.school01, fixed, type = "response", allow.new.levels=TRUE))


fixed <- data.lis.temp
fixed$affcat <- 5
fixed$fincon.lis.school01 <- 0 
aff5.cat0 <- mean(predict(campaign.lis.fincon.lis.school01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

campaign.fincon.lis.school01.cat0.diff <- aff5.cat0 - aff1.cat0 
campaign.fincon.lis.school01.cat0.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$fincon.lis.school01 <- 1 
aff1.cat1 <- mean(predict(campaign.lis.fincon.lis.school01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$fincon.lis.school01 <- 1 
aff5.cat1 <- mean(predict(campaign.lis.fincon.lis.school01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

campaign.fincon.lis.school01.cat1.diff <- aff5.cat1 - aff1.cat1 
campaign.fincon.lis.school01.cat1.diff

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "fincon.lis.school01", 
               "protestindex_css", "protest_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$fincon.lis.school01 <- 0 
aff1.cat0 <- mean(predict(protest.lis.fincon.lis.school01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$fincon.lis.school01 <- 0 
aff5.cat0 <- mean(predict(protest.lis.fincon.lis.school01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

protest.fincon.lis.school01.cat0.diff <- aff5.cat0 - aff1.cat0
protest.fincon.lis.school01.cat0.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$fincon.lis.school01 <- 1 
aff1.cat1 <- mean(predict(protest.lis.fincon.lis.school01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$fincon.lis.school01 <- 1 
aff5.cat1 <- mean(predict(protest.lis.fincon.lis.school01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

protest.fincon.lis.school01.cat1.diff <- aff5.cat1 - aff1.cat1 
protest.fincon.lis.school01.cat1.diff

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "fincon.lis.school01", 
               "elected01_gov", "commlead_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$fincon.lis.school01 <- 0 
aff1.cat0 <- mean(predict(elected.lis.fincon.lis.school01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$fincon.lis.school01 <- 0 
aff5.cat0 <- mean(predict(elected.lis.fincon.lis.school01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

elected.fincon.lis.school01.cat0.diff <- aff5.cat0 - aff1.cat0 
elected.fincon.lis.school01.cat0.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$fincon.lis.school01 <- 1 
aff1.cat1 <- mean(predict(elected.lis.fincon.lis.school01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$fincon.lis.school01 <- 1 
aff5.cat1 <- mean(predict(elected.lis.fincon.lis.school01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

elected.fincon.lis.school01.cat1.diff <- aff5.cat1 - aff1.cat1 
elected.fincon.lis.school01.cat1.diff

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "fincon.lis.school01", 
               "orglead01", "commlead_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$fincon.lis.school01 <- 0 
aff1.cat0 <- mean(predict(orglead.lis.fincon.lis.school01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$fincon.lis.school01 <- 0 
aff5.cat0 <- mean(predict(orglead.lis.fincon.lis.school01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

orglead.fincon.lis.school01.cat0.diff <- aff5.cat0 - aff1.cat0
orglead.fincon.lis.school01.cat0.diff 

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$fincon.lis.school01 <- 1 
aff1.cat1 <- mean(predict(orglead.lis.fincon.lis.school01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$fincon.lis.school01 <- 1 
aff5.cat1 <- mean(predict(orglead.lis.fincon.lis.school01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

orglead.fincon.lis.school01.cat1.diff <- aff5.cat1 - aff1.cat1
orglead.fincon.lis.school01.cat1.diff

# Dorms and dining halls index

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "closedfac", 
               "passive_index_css_avg", "passive_index_tfs_avg")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$closedfac <- 0 
aff1.cat0 <- mean(predict(passive.lis.closedfac, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$closedfac <- 0 
aff5.cat0 <- mean(predict(passive.lis.closedfac, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

passive.closedfac.cat0.diff <- aff5.cat0 - aff1.cat0 
passive.closedfac.cat0.diff


fixed <- data.lis.temp
fixed$affcat <- 1
fixed$closedfac <- 1 
aff1.cat1 <- mean(predict(passive.lis.closedfac, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$closedfac <- 1 
aff5.cat1 <- mean(predict(passive.lis.closedfac, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

passive.closedfac.cat1.diff <- aff5.cat1 - aff1.cat1 
passive.closedfac.cat1.diff

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "closedfac", 
               "voteprez2", "polaffairs_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$closedfac <- 0 
aff1.cat0 <- mean(predict(voting.lis.closedfac, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$closedfac <- 0 
aff5.cat0 <- mean(predict(voting.lis.closedfac, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

voting.closedfac.cat0.diff <- aff5.cat0 - aff1.cat0 
voting.closedfac.cat0.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$closedfac <- 1 
aff1.cat1 <- mean(predict(voting.lis.closedfac, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$closedfac <- 1 
aff5.cat1 <- mean(predict(voting.lis.closedfac, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

voting.closedfac.cat1.diff <- aff5.cat1 - aff1.cat1 
voting.closedfac.cat1.diff

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "closedfac", 
               "campaign_css", "campaign_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$closedfac <- 0 
aff1.cat0 <- mean(predict(campaign.lis.closedfac, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$closedfac <- 0 
aff5.cat0 <- mean(predict(campaign.lis.closedfac, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

campaign.closedfac.cat0.diff <- aff5.cat0 - aff1.cat0 
campaign.closedfac.cat0.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$closedfac <- 1 
aff1.cat1 <- mean(predict(campaign.lis.closedfac, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$closedfac <- 1 
aff5.cat1 <- mean(predict(campaign.lis.closedfac, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

campaign.closedfac.cat1.diff <- aff5.cat1 - aff1.cat1 
campaign.closedfac.cat1.diff

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "closedfac", 
               "protestindex_css", "protest_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$closedfac <- 0 
aff1.cat0 <- mean(predict(protest.lis.closedfac, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$closedfac <- 0 
aff5.cat0 <- mean(predict(protest.lis.closedfac, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

protest.closedfac.cat0.diff <- aff5.cat0 - aff1.cat0
protest.closedfac.cat0.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$closedfac <- 1 
aff1.cat1 <- mean(predict(protest.lis.closedfac, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$closedfac <- 1 
aff5.cat1 <- mean(predict(protest.lis.closedfac, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

protest.closedfac.cat1.diff <- aff5.cat1 - aff1.cat1 
protest.closedfac.cat1.diff

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "closedfac", 
               "elected01_gov", "commlead_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$closedfac <- 0 
aff1.cat0 <- mean(predict(elected.lis.closedfac, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$closedfac <- 0 
aff5.cat0 <- mean(predict(elected.lis.closedfac, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

elected.closedfac.cat0.diff <- aff5.cat0 - aff1.cat0 
elected.closedfac.cat0.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$closedfac <- 1 
aff1.cat1 <- mean(predict(elected.lis.closedfac, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$closedfac <- 1 
aff5.cat1 <- mean(predict(elected.lis.closedfac, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

elected.closedfac.cat1.diff <- aff5.cat1 - aff1.cat1 
elected.closedfac.cat1.diff

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "closedfac", 
               "orglead01", "commlead_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$closedfac <- 0 
aff1.cat0 <- mean(predict(orglead.lis.closedfac, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$closedfac <- 0 
aff5.cat0 <- mean(predict(orglead.lis.closedfac, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

orglead.closedfac.cat0.diff <- aff5.cat0 - aff1.cat0
orglead.closedfac.cat0.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$closedfac <- 1 
aff1.cat1 <- mean(predict(orglead.lis.closedfac, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$closedfac <- 1 
aff5.cat1 <- mean(predict(orglead.lis.closedfac, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

orglead.closedfac.cat1.diff <- aff5.cat1 - aff1.cat1
orglead.closedfac.cat1.diff

#######################
# Results for Table 2 #
#######################

list(passive.emohealth_tfs.cat0.diff, passive.emohealth_tfs.cat1.diff, (passive.emohealth_tfs.cat1.diff-passive.emohealth_tfs.cat0.diff) )
list(voting.emohealth_tfs.cat0.diff, voting.emohealth_tfs.cat1.diff, (voting.emohealth_tfs.cat1.diff-voting.emohealth_tfs.cat0.diff) )
list(campaign.emohealth_tfs.cat0.diff, campaign.emohealth_tfs.cat1.diff, (campaign.emohealth_tfs.cat1.diff-campaign.emohealth_tfs.cat0.diff) )
list(protest.emohealth_tfs.cat0.diff, protest.emohealth_tfs.cat1.diff, (protest.emohealth_tfs.cat1.diff-protest.emohealth_tfs.cat0.diff) )
list(elected.emohealth_tfs.cat0.diff, elected.emohealth_tfs.cat1.diff, (elected.emohealth_tfs.cat1.diff-elected.emohealth_tfs.cat0.diff) )
list(orglead.emohealth_tfs.cat0.diff, orglead.emohealth_tfs.cat1.diff, (orglead.emohealth_tfs.cat1.diff-orglead.emohealth_tfs.cat0.diff) )

list(passive.motivationlead_tfs.cat0.diff, passive.motivationlead_tfs.cat1.diff, (passive.motivationlead_tfs.cat1.diff-passive.motivationlead_tfs.cat0.diff) )
list(voting.motivationlead_tfs.cat0.diff, voting.motivationlead_tfs.cat1.diff, (voting.motivationlead_tfs.cat1.diff-voting.motivationlead_tfs.cat0.diff) )
list(campaign.motivationlead_tfs.cat0.diff, campaign.motivationlead_tfs.cat1.diff, (campaign.motivationlead_tfs.cat1.diff-campaign.motivationlead_tfs.cat0.diff) )
list(protest.motivationlead_tfs.cat0.diff, protest.motivationlead_tfs.cat1.diff, (protest.motivationlead_tfs.cat1.diff-protest.motivationlead_tfs.cat0.diff) )
list(elected.motivationlead_tfs.cat0.diff, elected.motivationlead_tfs.cat1.diff, (elected.motivationlead_tfs.cat1.diff-elected.motivationlead_tfs.cat0.diff) )

list(passive.academcomp_tfs01.cat0.diff, passive.academcomp_tfs01.cat1.diff, (passive.academcomp_tfs01.cat1.diff-passive.academcomp_tfs01.cat0.diff) )
list(voting.academcomp_tfs01.cat0.diff, voting.academcomp_tfs01.cat1.diff, (voting.academcomp_tfs01.cat1.diff-voting.academcomp_tfs01.cat0.diff) )
list(campaign.academcomp_tfs01.cat0.diff, campaign.academcomp_tfs01.cat1.diff, (campaign.academcomp_tfs01.cat1.diff-campaign.academcomp_tfs01.cat0.diff) )
list(protest.academcomp_tfs01.cat0.diff, protest.academcomp_tfs01.cat1.diff, (protest.academcomp_tfs01.cat1.diff-protest.academcomp_tfs01.cat0.diff) )
list(elected.academcomp_tfs01.cat0.diff, elected.academcomp_tfs01.cat1.diff, (elected.academcomp_tfs01.cat1.diff-elected.academcomp_tfs01.cat0.diff) )
list(orglead.academcomp_tfs01.cat0.diff, orglead.academcomp_tfs01.cat1.diff, (orglead.academcomp_tfs01.cat1.diff-orglead.academcomp_tfs01.cat0.diff) )

list(passive.soccon_tfs.cat0.diff, passive.soccon_tfs.cat1.diff, (passive.soccon_tfs.cat1.diff-passive.soccon_tfs.cat0.diff) )
list(voting.soccon_tfs.cat0.diff, voting.soccon_tfs.cat1.diff, (voting.soccon_tfs.cat1.diff-voting.soccon_tfs.cat0.diff) )
list(campaign.soccon_tfs.cat0.diff, campaign.soccon_tfs.cat1.diff, (campaign.soccon_tfs.cat1.diff-campaign.soccon_tfs.cat0.diff) )
list(protest.soccon_tfs.cat0.diff, protest.soccon_tfs.cat1.diff, (protest.soccon_tfs.cat1.diff-protest.soccon_tfs.cat0.diff) )
list(elected.soccon_tfs.cat0.diff, elected.soccon_tfs.cat1.diff, (elected.soccon_tfs.cat1.diff-elected.soccon_tfs.cat0.diff) )
list(orglead.soccon_tfs.cat0.diff, orglead.soccon_tfs.cat1.diff, (orglead.soccon_tfs.cat1.diff-orglead.soccon_tfs.cat0.diff) )

list(passive.soccon_tfs.cat0.agg.diff, passive.soccon_tfs.cat1.agg.diff, (passive.soccon_tfs.cat1.agg.diff-passive.soccon_tfs.cat0.agg.diff) )
list(voting.soccon_tfs.cat0.agg.diff, voting.soccon_tfs.cat1.agg.diff, (voting.soccon_tfs.cat1.agg.diff-voting.soccon_tfs.cat0.agg.diff) )
list(campaign.soccon_tfs.cat0.agg.diff, campaign.soccon_tfs.cat1.agg.diff, (campaign.soccon_tfs.cat1.agg.diff-campaign.soccon_tfs.cat0.agg.diff) )
list(protest.soccon_tfs.cat0.agg.diff, protest.soccon_tfs.cat1.agg.diff, (protest.soccon_tfs.cat1.agg.diff-protest.soccon_tfs.cat0.agg.diff) )
list(elected.soccon_tfs.cat0.agg.diff, elected.soccon_tfs.cat1.agg.diff, (elected.soccon_tfs.cat1.agg.diff-elected.soccon_tfs.cat0.agg.diff) )
list(orglead.soccon_tfs.cat0.agg.diff, orglead.soccon_tfs.cat1.agg.diff, (orglead.soccon_tfs.cat1.agg.diff-orglead.soccon_tfs.cat0.agg.diff) )

list(passive.collaidratio01.cat0.diff, passive.collaidratio01.cat1.diff, (passive.collaidratio01.cat1.diff-passive.collaidratio01.cat0.diff) )
list(voting.collaidratio01.cat0.diff, voting.collaidratio01.cat1.diff, (voting.collaidratio01.cat1.diff-voting.collaidratio01.cat0.diff) )
list(campaign.collaidratio01.cat0.diff, campaign.collaidratio01.cat1.diff, (campaign.collaidratio01.cat1.diff-campaign.collaidratio01.cat0.diff) )
list(protest.collaidratio01.cat0.diff, protest.collaidratio01.cat1.diff, (protest.collaidratio01.cat1.diff-protest.collaidratio01.cat0.diff) )
list(elected.collaidratio01.cat0.diff, elected.collaidratio01.cat1.diff, (elected.collaidratio01.cat1.diff-elected.collaidratio01.cat0.diff) )
list(orglead.collaidratio01.cat0.diff, orglead.collaidratio01.cat1.diff, (orglead.collaidratio01.cat1.diff-orglead.collaidratio01.cat0.diff) )

list(passive.fincon01.cat0.diff, passive.fincon01.cat1.diff, (passive.fincon01.cat1.diff-passive.fincon01.cat0.diff) )
list(voting.fincon01.cat0.diff, voting.fincon01.cat1.diff, (voting.fincon01.cat1.diff-voting.fincon01.cat0.diff) )
list(campaign.fincon01.cat0.diff, campaign.fincon01.cat1.diff, (campaign.fincon01.cat1.diff-campaign.fincon01.cat0.diff) )
list(protest.fincon01.cat0.diff, protest.fincon01.cat1.diff, (protest.fincon01.cat1.diff-protest.fincon01.cat0.diff) )
list(elected.fincon01.cat0.diff, elected.fincon01.cat1.diff, (elected.fincon01.cat1.diff-elected.fincon01.cat0.diff) )
list(orglead.fincon01.cat0.diff, orglead.fincon01.cat1.diff, (orglead.fincon01.cat1.diff-orglead.fincon01.cat0.diff) )

list(passive.fincon.lis.school01.cat0.diff, passive.fincon.lis.school01.cat1.diff, (passive.fincon.lis.school01.cat1.diff-passive.fincon.lis.school01.cat0.diff) )
list(voting.fincon.lis.school01.cat0.diff, voting.fincon.lis.school01.cat1.diff, (voting.fincon.lis.school01.cat1.diff-voting.fincon.lis.school01.cat0.diff) )
list(campaign.fincon.lis.school01.cat0.diff, campaign.fincon.lis.school01.cat1.diff, (campaign.fincon.lis.school01.cat1.diff-campaign.fincon.lis.school01.cat0.diff) )
list(protest.fincon.lis.school01.cat0.diff, protest.fincon.lis.school01.cat1.diff, (protest.fincon.lis.school01.cat1.diff-protest.fincon.lis.school01.cat0.diff) )
list(elected.fincon.lis.school01.cat0.diff, elected.fincon.lis.school01.cat1.diff, (elected.fincon.lis.school01.cat1.diff-elected.fincon.lis.school01.cat0.diff) )
list(orglead.fincon.lis.school01.cat0.diff, orglead.fincon.lis.school01.cat1.diff, (orglead.fincon.lis.school01.cat1.diff-orglead.fincon.lis.school01.cat0.diff) )

list(passive.closedfac.cat0.diff, passive.closedfac.cat1.diff, (passive.closedfac.cat1.diff-passive.closedfac.cat0.diff) )
list(voting.closedfac.cat0.diff, voting.closedfac.cat1.diff, (voting.closedfac.cat1.diff-voting.closedfac.cat0.diff) )
list(campaign.closedfac.cat0.diff, campaign.closedfac.cat1.diff, (campaign.closedfac.cat1.diff-campaign.closedfac.cat0.diff) )
list(protest.closedfac.cat0.diff, protest.closedfac.cat1.diff, (protest.closedfac.cat1.diff-protest.closedfac.cat0.diff) )
list(elected.closedfac.cat0.diff, elected.closedfac.cat1.diff, (elected.closedfac.cat1.diff-elected.closedfac.cat0.diff) )
list(orglead.closedfac.cat0.diff, orglead.closedfac.cat1.diff, (orglead.closedfac.cat1.diff-orglead.closedfac.cat0.diff) )

##########################################################################################
############################ APPENDIX ##################################################
##########################################################################################
##########################################################################################

####################
# Appendix Table 5 #
####################

## correlations between campus affluence and school/cohort level variables
cor(csscohort$hitestscoreper, csscohort$affcat, use="complete.obs", method="spearman")
cor(csscohort$hiasianper, csscohort$affcat, use="complete.obs", method="spearman") 
cor(csscohort$hihispanicper, csscohort$affcat, use="complete.obs", method="spearman") 
cor(csscohort$hiothraceper, csscohort$affcat, use="complete.obs", method="spearman") 
cor(csscohort$hijewishper, csscohort$affcat, use="complete.obs", method="spearman") 
cor(csscohort$hicatholicper, csscohort$affcat, use="complete.obs", method="spearman") 
cor(csscohort$hievangelicalper, csscohort$affcat, use="complete.obs", method="spearman") 
cor(csscohort$hiotherornoreligper, csscohort$affcat, use="complete.obs", method="spearman") 
cor(csscohort$notenglishfirstper, csscohort$affcat, use="complete.obs", method="spearman") 
cor(csscohort$age17orlessper, csscohort$affcat, use="complete.obs", method="spearman") 
cor(csscohort$age19per, csscohort$affcat, use="complete.obs", method="spearman") 
cor(csscohort$age20per, csscohort$affcat, use="complete.obs", method="spearman") 
cor(csscohort$socscitfsper, csscohort$affcat, use="complete.obs", method="spearman") 
cor(csscohort$humantfsper, csscohort$affcat, use="complete.obs", method="spearman") 
cor(csscohort$sciencetfsper, csscohort$affcat, use="complete.obs", method="spearman") 
cor(csscohort$businesstfsper, csscohort$affcat, use="complete.obs", method="spearman") 
cor(csscohort$makemoneyvimpper, csscohort$affcat, use="complete.obs", method="spearman") 
cor(csscohort$mostlyfemale, csscohort$affcat, use="complete.obs", method="spearman") 
cor(csscohort$mostlyblack, csscohort$affcat, use="complete.obs", method="spearman") 
cor(csscohort$largesb, csscohort$affcat, use="complete.obs", method="spearman") 
cor(csscohort$public, csscohort$affcat, use="complete.obs", method="spearman") 
cor(csscohort$college, csscohort$affcat, use="complete.obs", method="spearman") 
cor(csscohort$neast, csscohort$affcat, use="complete.obs", method="spearman") 

## correlation between campus affluence and indiviudal variables
cor(data.lis$hitestscore, data.lis$affcat, use="complete.obs", method="spearman") 
cor(data.his$hitestscore, data.his$affcat, use="complete.obs", method="spearman")  

cor(data.lis$female, data.lis$affcat, use="complete.obs", method="spearman")
cor(data.his$female, data.his$affcat, use="complete.obs", method="spearman") 

cor(data.lis$asian, data.lis$affcat, use="complete.obs", method="spearman")
cor(data.his$asian, data.his$affcat, use="complete.obs", method="spearman") 

cor(data.lis$hispanic, data.lis$affcat, use="complete.obs", method="spearman")
cor(data.his$hispanic, data.his$affcat, use="complete.obs", method="spearman") 

cor(data.lis$black, data.lis$affcat, use="complete.obs", method="spearman")
cor(data.his$black, data.his$affcat, use="complete.obs", method="spearman") 

cor(data.lis$othrace, data.lis$affcat, use="complete.obs", method="spearman")
cor(data.his$othrace, data.his$affcat, use="complete.obs", method="spearman") 

cor(data.lis$jewish, data.lis$affcat, use="complete.obs", method="spearman")
cor(data.his$jewish, data.his$affcat, use="complete.obs", method="spearman")

cor(data.lis$catholic, data.lis$affcat, use="complete.obs", method="spearman")
cor(data.his$catholic, data.his$affcat, use="complete.obs", method="spearman")

cor(data.lis$evangelical, data.lis$affcat, use="complete.obs", method="spearman")
cor(data.his$evangelical, data.his$affcat, use="complete.obs", method="spearman")

cor(data.lis$otherornorelig, data.lis$affcat, use="complete.obs", method="spearman")
cor(data.his$otherornorelig, data.his$affcat, use="complete.obs", method="spearman")

cor(data.lis$notenglishfirst, data.lis$affcat, use="complete.obs", method="spearman")
cor(data.his$notenglishfirst, data.his$affcat, use="complete.obs", method="spearman")

cor(data.lis$age17orless, data.lis$affcat, use="complete.obs", method="spearman")
cor(data.his$age17orless, data.his$affcat, use="complete.obs", method="spearman")

cor(data.lis$age19, data.lis$affcat, use="complete.obs", method="spearman")
cor(data.his$age19, data.his$affcat, use="complete.obs", method="spearman")

cor(data.lis$age20, data.lis$affcat, use="complete.obs", method="spearman")
cor(data.his$age20, data.his$affcat, use="complete.obs", method="spearman")

cor(data.lis$socscitfs, data.lis$affcat, use="complete.obs", method="spearman")
cor(data.his$socscitfs, data.his$affcat, use="complete.obs", method="spearman")

cor(data.lis$humantfs, data.lis$affcat, use="complete.obs", method="spearman")
cor(data.his$humantfs, data.his$affcat, use="complete.obs", method="spearman")

cor(data.lis$sciencetfs, data.lis$affcat, use="complete.obs", method="spearman")
cor(data.his$sciencetfs, data.his$affcat, use="complete.obs", method="spearman")

cor(data.lis$businesstfs, data.lis$affcat, use="complete.obs", method="spearman")
cor(data.his$businesstfs, data.his$affcat, use="complete.obs", method="spearman")

cor(data.lis$makemoneyvimp, data.lis$affcat, use="complete.obs", method="spearman")
cor(data.his$makemoneyvimp, data.his$affcat, use="complete.obs", method="spearman")

cor(data.lis$poldiscuss_tfs_full, data.lis$affcat, use="complete.obs", method="spearman")
cor(data.his$poldiscuss_tfs_full, data.his$affcat, use="complete.obs", method="spearman") 

cor(data.lis$passive_index_tfs_avg, data.lis$affcat, use="complete.obs", method="spearman")
cor(data.his$passive_index_tfs_avg, data.his$affcat, use="complete.obs", method="spearman") 

cor(data.lis$polaffairs_tfs, data.lis$affcat, use="complete.obs", method="spearman")
cor(data.his$polaffairs_tfs, data.his$affcat, use="complete.obs", method="spearman") 

cor(data.lis$campaign_tfs, data.lis$affcat, use="complete.obs", method="spearman")
cor(data.his$campaign_tfs, data.his$affcat, use="complete.obs", method="spearman") 

cor(data.lis$commlead_tfs, data.lis$affcat, use="complete.obs", method="spearman")
cor(data.his$commlead_tfs, data.his$affcat, use="complete.obs", method="spearman") 

cor(data.lis$protest_tfs, data.lis$affcat, use="complete.obs", method="spearman")
cor(data.his$protest_tfs, data.his$affcat, use="complete.obs", method="spearman") 

#####################
# Appendix Figure 2 #
#####################

## LIS

## regress senior year vote for prez onto freshman year pol ffairs, include year fixed effects, and school and cohort random int.
protest.lis <- glmer(protestindex_css ~ protest_tfs +
                       factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), 
                     control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), 
                     data = data.lis)

protest.lis

## create predicted values
modelvars <- c("protestindex_css", "protest_tfs", "YEAR", "ACERECODE", "ace_year")
modelvars

data.lis2 <- data.lis[complete.cases(data.lis[,modelvars]),]

data.lis2$predictedprotest <- predict(protest.lis, data.lis2, re.form=NULL, type = "response")
summary(data.lis2$predictedprotest)

protest.2 <- ggplot(data.lis2, aes(x=affper, y=predictedprotest)) +
  geom_point(size = 1, na.rm = T) +
  labs(title="Protest (LIS)",
       x ="Proportion affluent", y = "Adjusted CSS value") +
  geom_smooth(method = lm, col = "green")  + theme_grey(base_size = 14)

protest.2

## HIS

## regress senior year vote for prez onto freshman year pol ffairs, include year fixed effects, and school and cohort random int.
protest.his <- glmer(protestindex_css ~ protest_tfs +
                       factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), 
                     control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.his)
protest.his

## create predicted values
modelvars <- c("protestindex_css", "protest_tfs", "YEAR", "ACERECODE", "ace_year")
modelvars

data.his2 <- data.his[complete.cases(data.his[,modelvars]),]

data.his2$predictedprotest <- predict(protest.his, data.his2, re.form=NULL, type = "response")
summary(data.his2$predictedprotest)

protest.3 <- ggplot(data.his2, aes(x=affper, y=predictedprotest)) +
  geom_point(size = 1, na.rm = T) +
  labs(title="Protest (HIS)",
       x ="Proportion affluent", y = "Adjusted CSS value")+
  geom_smooth(method = lm, col = "green")  + theme_grey(base_size = 14)

protest.3 

summary(csscohort$campaign_css) ## senior year
summary(csscohort$campaign_tfs) ## freshman year

## regress senior year vote for prez onto freshman year pol ffairs, include year fixed effects, and school and cohort random int.
campaign.lis <- glmer(campaign_css ~ campaign_tfs +
                        factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), 
                      control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), 
                      data = data.lis)

campaign.lis

## create predicted values
modelvars <- c("campaign_css", "campaign_tfs", "YEAR", "ACERECODE", "ace_year")
modelvars

data.lis2 <- data.lis[complete.cases(data.lis[,modelvars]),]

data.lis2$predictedcampaign <- predict(campaign.lis, data.lis2, re.form=NULL, type = "response")

campaign.2 <- ggplot(data.lis2, aes(x=affper, y=predictedcampaign)) +
  geom_point(size = 1, na.rm = T) +
  labs(title="Campaign (LIS)",
       x ="Proportion affluent", y = "Adjusted CSS value") +
  geom_smooth(method = lm, col = "green")  + theme_grey(base_size = 14)

campaign.2

## HIS

## regress senior year vote for prez onto freshman year pol ffairs, include year fixed effects, and school and cohort random int.
campaign.his <- glmer(campaign_css ~ campaign_tfs +
                        factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), 
                      control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.his)
campaign.his

## create predicted values
modelvars <- c("campaign_css", "campaign_tfs", "YEAR", "ACERECODE", "ace_year")
modelvars

data.his2 <- data.his[complete.cases(data.his[,modelvars]),]

data.his2$predictedcampaign <- predict(campaign.his, data.his2, re.form=NULL, type = "response")

campaign.3 <- ggplot(data.his2, aes(x=affper, y=predictedcampaign)) +
  geom_point(size = 1, na.rm = T) +
  labs(title="Campaign (HIS)",
       x ="Proportion affluent", y = "Adjusted CSS value")+
  geom_smooth(method = lm, col = "green")  + theme_grey(base_size = 14)

campaign.3 

## regress senior year vote for prez onto freshman year pol ffairs, include year fixed effects, and school and cohort random int.
passive.lis <- lmer(passive_index_css_avg ~ passive_index_tfs_avg +
                      factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), 
                    data = data.lis)

passive.lis

## create predicted values
modelvars <- c("passive_index_css_avg", "passive_index_tfs_avg", "YEAR", "ACERECODE", "ace_year")
modelvars

data.lis2 <- data.lis[complete.cases(data.lis[,modelvars]),]

data.lis2$predictedpassive <- predict(passive.lis, data.lis2, re.form=NULL, type = "response")

passive.2 <- ggplot(data.lis2, aes(x=affper, y=predictedpassive)) +
  geom_point(size = 1, na.rm = T) +
  labs(title="Passive Engagement (LIS)",
       x ="Proportion affluent", y = "Adjusted CSS value") +
  geom_smooth(method = lm, col = "green")  + theme_grey(base_size = 14)

passive.2

## HIS

## regress senior year vote for prez onto freshman year pol ffairs, include year fixed effects, and school and cohort random int.
passive.his <- glmer(passive_index_css_avg ~ passive_index_tfs_avg +
                       factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), data = data.his)
passive.his

## create predicted values
modelvars <- c("passive_index_css_avg", "passive_index_tfs_avg", "YEAR", "ACERECODE", "ace_year")
modelvars

data.his2 <- data.his[complete.cases(data.his[,modelvars]),]

data.his2$predictedpassive <- predict(passive.his, data.his2, re.form=NULL, type = "response")

passive.3 <- ggplot(data.his2, aes(x=affper, y=predictedpassive)) +
  geom_point(size = 1, na.rm = T) +
  labs(title="Passive Engagement (HIS)",
       x ="Proportion affluent", y = "Adjusted CSS value")+
  geom_smooth(method = lm, col = "green")  + theme_grey(base_size = 14)

passive.3 

scatter1_individual <- grid.arrange(protest.2, protest.3,
                                    passive.2, passive.3,
                                    campaign.2, campaign.3, nrow=3)

ggsave("scatter1_individual_nochange.png",
       scatter1_individual,
       width = 8,
       height = 8,
       dpi = 1200)

#####################
# Appendix Figure 3 #
#####################

######################
# Voted in an election 
######################

## LIS

## regress senior year vote for prez onto freshman year pol ffairs, include year fixed effects, and school and cohort random int.
voteprez.lis <- glmer(voteprez2 ~ polaffairs_tfs +
                        factor(YEAR) + (1 | ACERECODE) 
                      + (1 | ace_year), family = binomial("logit"), 
                      control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), 
                      data = data.lis)

voteprez.lis

## create predicted values
modelvars <- c("voteprez2", "polaffairs_tfs", "YEAR", "ACERECODE", "ace_year")
modelvars

csscohort2 <- csscohort[complete.cases(csscohort[,modelvars]),]

data.lis.temp <- csscohort2[csscohort2$parinc == "Low-Income",]
head(data.lis.temp)

data.lis.temp$predictedvote <- predict(voteprez.lis, data.lis.temp, re.form=NULL, type = "response")
summary(data.lis.temp$predictedvote)

vote.2 <- ggplot(data.lis.temp, aes(x=affper, y=predictedvote)) +
  geom_point(size = 1, na.rm = T) +
  labs(title="Voting (LIS)",
       x ="Proportion affluent", y = "Adjusted CSS value") +
  geom_smooth(method = lm, col = "green")  + theme_grey(base_size = 14)

vote.2 

## HIS

## regress senior year vote for prez onto freshman year pol ffairs, include year fixed effects, and school and cohort random int.
voteprez.his <- glmer(voteprez2 ~ polaffairs_tfs +
                        factor(YEAR) + (1 | ACERECODE) 
                      + (1 | ace_year), family = binomial("logit"), 
                      control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.his)
voteprez.his

## create predicted values
modelvars <- c("voteprez2", "polaffairs_tfs", "YEAR", "ACERECODE", "ace_year")
modelvars

csscohort2 <- csscohort[complete.cases(csscohort[,modelvars]),]

data.his.temp <- csscohort2[csscohort2$parinc == "High-Income",]
head(data.his.temp)

data.his.temp$predictedvote <- predict(voteprez.his, data.his.temp, re.form=NULL, type = "response")
summary(data.his.temp$predictedvote)

vote.3 <- ggplot(data.his.temp, aes(x=affper, y=predictedvote)) +
  geom_point(size = 1, na.rm = T) +
  labs(title="Voting (HIS)",
       x ="Proportion affluent", y = "Adjusted CSS value")+
  geom_smooth(method = lm, col = "green")  + theme_grey(base_size = 14)

vote.3 

###########################
# leader of an organization 
###########################

## LIS

summary(csscohort$orglead01)

orglead.lis <- glmer(orglead01 ~ commlead_tfs +
                       factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)
orglead.lis       

## create predicted values
modelvars <- c("orglead01", "commlead_tfs", "YEAR", "ACERECODE", "ace_year")
modelvars

csscohort2 <- csscohort[complete.cases(csscohort[,modelvars]),]

data.lis.temp <- csscohort2[csscohort2$parinc == "Low-Income",]
head(data.lis.temp)

data.lis.temp$predictedorglead <- predict(orglead.lis, data.lis.temp, re.form=NULL, type = "response")
summary(data.lis.temp$predictedorglead)

orglead.2 <- ggplot(data.lis.temp, aes(x=affper, y=predictedorglead)) +
  geom_point(size = 1, na.rm = T) +
  labs(title="Organizational leadership (LIS)",
       x ="Proportion affluent", y = "Adjusted CSS value")+
  geom_smooth(method = lm, col = "green")  + theme_grey(base_size = 14)

orglead.2 

## HIS
orglead.his <- glmer(orglead01 ~ commlead_tfs +
                       factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.his)
orglead.his       

## create predicted values
modelvars <- c("orglead01", "commlead_tfs", "YEAR", "ACERECODE", "ace_year")
modelvars

csscohort2 <- csscohort[complete.cases(csscohort[,modelvars]),]

data.his.temp <- csscohort2[csscohort2$parinc == "High-Income",]
head(data.his.temp)

data.his.temp$predictedorglead <- predict(orglead.his, data.his.temp, re.form=NULL, type = "response")
summary(data.his.temp$predictedorglead)

orglead.3 <- ggplot(data.his.temp, aes(x=affper, y=predictedorglead)) +
  geom_point(size = 1, na.rm = T) +
  labs(title="Organizational leadership (HIS)",
       x ="Proportion affluent", y = "Adjusted CSS value")+
  geom_smooth(method = lm, col = "green")  + theme_grey(base_size = 14)

orglead.3 

########################
# Elected to student gov 
########################

## LIS 

elected.lis <- glmer(elected01_gov ~ commlead_tfs + 
                       factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), 
                     family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), 
                     data = data.lis)

elected.lis                      

## create predicted values
modelvars <- c("elected01_gov", "commlead_tfs", "YEAR", "ACERECODE", "ace_year")
modelvars

csscohort2 <- csscohort[complete.cases(csscohort[,modelvars]),]

data.lis.temp <- csscohort2[csscohort2$parinc == "Low-Income",]
head(data.lis.temp)

data.lis.temp$predictedelected <- predict(elected.lis, data.lis.temp, re.form=NULL, type = "response")
summary(data.lis.temp$predictedelected)

elected.2 <- ggplot(data.lis.temp, aes(x=affper, y=predictedelected)) +
  geom_point(size = 1, na.rm = T) +
  labs(title="Elected to student office (LIS)",
       x ="Proportion affluent", y = "Adjusted CSS value") +
  geom_smooth(method = lm, col = "green")  + theme_grey(base_size = 14)

elected.2 

## HIS
summary(csscohort$elected01_gov) ## correct measure

elected.his <- glmer(elected01_gov ~ commlead_tfs + 
                       factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), 
                     family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), 
                     data = data.his)

elected.his                      

## create predicted values
modelvars <- c("elected01_gov", "commlead_tfs", "YEAR", "ACERECODE", "ace_year")
modelvars

csscohort2 <- csscohort[complete.cases(csscohort[,modelvars]),]

data.his.temp <- csscohort2[csscohort2$parinc == "High-Income",]
head(data.his.temp)

data.his.temp$predictedelected <- predict(elected.his, data.his.temp, re.form=NULL, type = "response")
summary(data.his.temp$predictedelected)

elected.3 <- ggplot(data.his.temp, aes(x=affper, y=predictedelected)) +
  geom_point(size = 1, na.rm = T) +
  labs(title="Elected to student office (HIS)",
       x ="Proportion affluent", y = "Adjusted CSS value")+
  geom_smooth(method = lm, col = "green")  + theme_grey(base_size = 14)

elected.3 

## single plot
grid.arrange(orglead.2, orglead.3,
             vote.2, vote.3,
             elected.2, elected.3, nrow=3)

####################
# Appendix Table 6 #
####################

#############
# Mediation #
#############

# Packages "lmertest" and "psych" must be detached for mediation analysis to work

###########################
# Psychological Mechanism #
###########################

###############################
# Cohort Emotional Health CSS #
###############################

# Only include observations where mediator is observed

csscohort2 <- csscohort[is.na(csscohort$emohealth_css_cohort) == F,]

# Create datasets 

data.lis.m <- csscohort2[csscohort2$parinc == "Low-Income",]
data.mis.m <- csscohort2[csscohort2$parinc == "Middle-Income",]
data.his.m <- csscohort2[csscohort2$parinc == "High-Income",]

##############
# Passive DV #
##############

# Mediator Models, regressing mediator on school affluence and controls

med.passive.lis.emohealth_css_cohort.DV  <- lmer(emohealth_css_cohort ~ medtreat + passive_index_tfs_avg + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.lis.m[!is.na(data.lis.m$passive_index_css_avg),])

med.passive.mis.emohealth_css_cohort.DV  <- lmer(emohealth_css_cohort ~ medtreat + passive_index_tfs_avg + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.mis.m[!is.na(data.mis.m$passive_index_css_avg),])

med.passive.his.emohealth_css_cohort.DV  <- lmer(emohealth_css_cohort ~ medtreat + passive_index_tfs_avg + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.his.m[!is.na(data.his.m$passive_index_css_avg),])

# Outcome Models, regressing outcome on mediator, school affluence, and controls

med.passive.lis.emohealth_css_cohort.stand  <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + emohealth_css_cohort + medtreat +
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.lis.m)

med.passive.mis.emohealth_css_cohort.stand  <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + emohealth_css_cohort + medtreat +
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.mis.m)

med.passive.his.emohealth_css_cohort.stand  <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + emohealth_css_cohort + medtreat +
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.his.m)

## Run Mediation summary (exact numbers may vary due to simulations)

med.passive.emohealth_css_cohort.lis <- mediate(model.m = med.passive.lis.emohealth_css_cohort.DV, model.y = med.passive.lis.emohealth_css_cohort.stand, treat = "medtreat", 
                                               mediator = "emohealth_css_cohort", sims = 500 )
summary(med.passive.emohealth_css_cohort.lis)

med.passive.emohealth_css_cohort.mis <- mediate(model.m = med.passive.mis.emohealth_css_cohort.DV, model.y = med.passive.mis.emohealth_css_cohort.stand, treat = "medtreat", 
                                               mediator = "emohealth_css_cohort", sims = 500 )
summary(med.passive.emohealth_css_cohort.mis)

med.passive.emohealth_css_cohort.his <- mediate(model.m = med.passive.his.emohealth_css_cohort.DV, model.y = med.passive.his.emohealth_css_cohort.stand, treat = "medtreat", 
                                               mediator = "emohealth_css_cohort", sims = 500 )
summary(med.passive.emohealth_css_cohort.his)

##########
# Voting #
##########

## Mediator Models, regressing mediator on school affluence and controls

med.voteprez2.lis.emohealth_css_cohort.DV  <- lmer(emohealth_css_cohort ~ medtreat + polaffairs_tfs + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.lis.m[!is.na(data.lis.m$voteprez2),])

med.voteprez2.mis.emohealth_css_cohort.DV  <- lmer(emohealth_css_cohort ~ medtreat + polaffairs_tfs + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.mis.m[!is.na(data.mis.m$voteprez2),])

med.voteprez2.his.emohealth_css_cohort.DV  <- lmer(emohealth_css_cohort ~ medtreat + polaffairs_tfs + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.his.m[!is.na(data.his.m$voteprez2),])

## Outcome Models, regressing outcome on mediator, school affluence, and controls

med.voteprez2.lis.emohealth_css_cohort.stand  <- glmer(voteprez2 ~ polaffairs_tfs + emohealth_css_cohort + medtreat +
                  polaffairs_tfs +  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE), family = binomial("logit"),control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                  data = data.lis.m)


med.voteprez2.mis.emohealth_css_cohort.stand  <- glmer(voteprez2 ~ polaffairs_tfs + emohealth_css_cohort + medtreat +
                  polaffairs_tfs +  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE), family = binomial("logit"),control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                  data = data.mis.m)

med.voteprez2.his.emohealth_css_cohort.stand  <- glmer(voteprez2 ~ polaffairs_tfs + emohealth_css_cohort + medtreat +
                  polaffairs_tfs +  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE), family = binomial("logit"),control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                  data = data.his.m)

## Run Mediation summary (exact numbers may vary due to simulations)
med.voteprez2.emohealth_css_cohort.lis <- mediate(model.m = med.voteprez2.lis.emohealth_css_cohort.DV, model.y = med.voteprez2.lis.emohealth_css_cohort.stand, treat = "medtreat", 
                                        mediator = "emohealth_css_cohort", sims = 500 )
summary(med.voteprez2.emohealth_css_cohort.lis)

med.voteprez2.emohealth_css_cohort.mis <- mediate(model.m = med.voteprez2.mis.emohealth_css_cohort.DV, model.y = med.voteprez2.mis.emohealth_css_cohort.stand, treat = "medtreat", 
                                        mediator = "emohealth_css_cohort", sims = 500 )
summary(med.voteprez2.emohealth_css_cohort.mis)

med.voteprez2.emohealth_css_cohort.his <- mediate(model.m = med.voteprez2.his.emohealth_css_cohort.DV, model.y = med.voteprez2.his.emohealth_css_cohort.stand, treat = "medtreat", 
                                        mediator = "emohealth_css_cohort", sims = 500 )
summary(med.voteprez2.emohealth_css_cohort.his)

##############
# Protesting #
##############

## Mediator Models, regressing mediator on school affluence and controls

med.protest.lis.emohealth_css_cohort.DV  <- lmer(emohealth_css_cohort ~ medtreat + protest_tfs + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE), data = data.lis.m[!is.na(data.lis.m$protestindex_css),])

med.protest.mis.emohealth_css_cohort.DV  <- lmer(emohealth_css_cohort ~ medtreat + protest_tfs + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE), data = data.mis.m[!is.na(data.mis.m$protestindex_css),])

nobs(med.protest.mis.emohealth_css_cohort.DV)

med.protest.his.emohealth_css_cohort.DV  <- lmer(emohealth_css_cohort ~ medtreat + protest_tfs + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE), data = data.his.m[!is.na(data.his.m$protestindex_css),])

## Outcome Models, regressing outcome on mediator, school affluence, and controls

med.protest.lis.emohealth_css_cohort.stand  <- glmer(protestindex_css ~ protest_tfs + emohealth_css_cohort + medtreat +
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE),family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                  data = data.lis.m)

med.protest.mis.emohealth_css_cohort.stand  <- glmer(protestindex_css ~ protest_tfs + emohealth_css_cohort + medtreat +
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE),family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                  data = data.mis.m)

nobs(med.protest.mis.emohealth_css_cohort.stand)

med.protest.his.emohealth_css_cohort.stand  <- glmer(protestindex_css ~ protest_tfs + emohealth_css_cohort + medtreat +
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE),family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                  data = data.his.m)

## Run Mediation summary (exact numbers may vary due to simulations)
med.protest.emohealth_css_cohort.lis <- mediate(model.m = med.protest.lis.emohealth_css_cohort.DV, model.y = med.protest.lis.emohealth_css_cohort.stand, treat = "medtreat", 
                                               mediator = "emohealth_css_cohort", sims = 500 )
summary(med.protest.emohealth_css_cohort.lis)

med.protest.emohealth_css_cohort.mis <- mediate(model.m = med.protest.mis.emohealth_css_cohort.DV, model.y = med.protest.mis.emohealth_css_cohort.stand, treat = "medtreat", 
                                               mediator = "emohealth_css_cohort", sims = 500 )
summary(med.protest.emohealth_css_cohort.mis)

med.protest.emohealth_css_cohort.his <- mediate(model.m = med.protest.his.emohealth_css_cohort.DV, model.y = med.protest.his.emohealth_css_cohort.stand, treat = "medtreat", 
                                               mediator = "emohealth_css_cohort", sims = 500 )
summary(med.protest.emohealth_css_cohort.his)

###################################
# Cohort Emotional Health TFS-CSS #
###################################

# Only include observations where mediator is observed

csscohort2 <- csscohort[is.na(csscohort$emohealth_chg_cohort) == F,]

# Create datasets 

data.lis.m <- csscohort2[csscohort2$parinc == "Low-Income",]
data.mis.m <- csscohort2[csscohort2$parinc == "Middle-Income",]
data.his.m <- csscohort2[csscohort2$parinc == "High-Income",]

##############
# Passive DV #
##############

# Mediator Models, regressing mediator on school affluence and controls

med.passive.lis.emohealth_chg_cohort.DV  <- lmer(emohealth_chg_cohort ~ medtreat + passive_index_tfs_avg + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.lis.m[!is.na(data.lis.m$passive_index_css_avg),])

med.passive.mis.emohealth_chg_cohort.DV  <- lmer(emohealth_chg_cohort ~ medtreat + passive_index_tfs_avg + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.mis.m[!is.na(data.mis.m$passive_index_css_avg),])

med.passive.his.emohealth_chg_cohort.DV  <- lmer(emohealth_chg_cohort ~ medtreat + passive_index_tfs_avg + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.his.m[!is.na(data.his.m$passive_index_css_avg),])

# Outcome Models, regressing outcome on mediator, school affluence, and controls

med.passive.lis.emohealth_chg_cohort.stand  <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + emohealth_chg_cohort + medtreat +
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.lis.m)

med.passive.mis.emohealth_chg_cohort.stand  <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + emohealth_chg_cohort + medtreat +
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.mis.m)

med.passive.his.emohealth_chg_cohort.stand  <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + emohealth_chg_cohort + medtreat +
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.his.m)

## Run Mediation summary (exact numbers may vary due to simulations)

med.passive.emohealth_chg_cohort.lis <- mediate(model.m = med.passive.lis.emohealth_chg_cohort.DV, model.y = med.passive.lis.emohealth_chg_cohort.stand, treat = "medtreat", 
                                               mediator = "emohealth_chg_cohort", sims = 500 )
summary(med.passive.emohealth_chg_cohort.lis)

med.passive.emohealth_chg_cohort.mis <- mediate(model.m = med.passive.mis.emohealth_chg_cohort.DV, model.y = med.passive.mis.emohealth_chg_cohort.stand, treat = "medtreat", 
                                               mediator = "emohealth_chg_cohort", sims = 500 )
summary(med.passive.emohealth_chg_cohort.mis)

med.passive.emohealth_chg_cohort.his <- mediate(model.m = med.passive.his.emohealth_chg_cohort.DV, model.y = med.passive.his.emohealth_chg_cohort.stand, treat = "medtreat", 
                                               mediator = "emohealth_chg_cohort", sims = 500 )
summary(med.passive.emohealth_chg_cohort.his)

##########
# Voting #
##########

## Mediator Models, regressing mediator on school affluence and controls

med.voteprez2.lis.emohealth_chg_cohort.DV  <- lmer(emohealth_chg_cohort ~ medtreat + polaffairs_tfs + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.lis.m[!is.na(data.lis.m$voteprez2),])

med.voteprez2.mis.emohealth_chg_cohort.DV  <- lmer(emohealth_chg_cohort ~ medtreat + polaffairs_tfs + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.mis.m[!is.na(data.mis.m$voteprez2),])

med.voteprez2.his.emohealth_chg_cohort.DV  <- lmer(emohealth_chg_cohort ~ medtreat + polaffairs_tfs + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.his.m[!is.na(data.his.m$voteprez2),])

## Outcome Models, regressing outcome on mediator, school affluence, and controls

med.voteprez2.lis.emohealth_chg_cohort.stand  <- glmer(voteprez2 ~ polaffairs_tfs + emohealth_chg_cohort + medtreat +
                  polaffairs_tfs +  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE), family = binomial("logit"),control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                  data = data.lis.m)


med.voteprez2.mis.emohealth_chg_cohort.stand  <- glmer(voteprez2 ~ polaffairs_tfs + emohealth_chg_cohort + medtreat +
                  polaffairs_tfs +  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE), family = binomial("logit"),control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                  data = data.mis.m)

med.voteprez2.his.emohealth_chg_cohort.stand  <- glmer(voteprez2 ~ polaffairs_tfs + emohealth_chg_cohort + medtreat +
                  polaffairs_tfs +  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE), family = binomial("logit"),control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                  data = data.his.m)

## Run Mediation summary (exact numbers may vary due to simulations)
med.voteprez2.emohealth_chg_cohort.lis <- mediate(model.m = med.voteprez2.lis.emohealth_chg_cohort.DV, model.y = med.voteprez2.lis.emohealth_chg_cohort.stand, treat = "medtreat", 
                                        mediator = "emohealth_chg_cohort", sims = 500 )
summary(med.voteprez2.emohealth_chg_cohort.lis)

med.voteprez2.emohealth_chg_cohort.mis <- mediate(model.m = med.voteprez2.mis.emohealth_chg_cohort.DV, model.y = med.voteprez2.mis.emohealth_chg_cohort.stand, treat = "medtreat", 
                                        mediator = "emohealth_chg_cohort", sims = 500 )
summary(med.voteprez2.emohealth_chg_cohort.mis)

med.voteprez2.emohealth_chg_cohort.his <- mediate(model.m = med.voteprez2.his.emohealth_chg_cohort.DV, model.y = med.voteprez2.his.emohealth_chg_cohort.stand, treat = "medtreat", 
                                        mediator = "emohealth_chg_cohort", sims = 500 )
summary(med.voteprez2.emohealth_chg_cohort.his)

##############
# Protesting #
##############

## Mediator Models, regressing mediator on school affluence and controls

med.protest.lis.emohealth_chg_cohort.DV  <- lmer(emohealth_chg_cohort ~ medtreat + protest_tfs + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE), data = data.lis.m[!is.na(data.lis.m$protestindex_css),])

med.protest.mis.emohealth_chg_cohort.DV  <- lmer(emohealth_chg_cohort ~ medtreat + protest_tfs + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE), data = data.mis.m[!is.na(data.mis.m$protestindex_css),])

nobs(med.protest.mis.emohealth_chg_cohort.DV)

med.protest.his.emohealth_chg_cohort.DV  <- lmer(emohealth_chg_cohort ~ medtreat + protest_tfs + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE), data = data.his.m[!is.na(data.his.m$protestindex_css),])

## Outcome Models, regressing outcome on mediator, school affluence, and controls

med.protest.lis.emohealth_chg_cohort.stand  <- glmer(protestindex_css ~ protest_tfs + emohealth_chg_cohort + medtreat +
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE),family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                  data = data.lis.m)

med.protest.mis.emohealth_chg_cohort.stand  <- glmer(protestindex_css ~ protest_tfs + emohealth_chg_cohort + medtreat +
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE),family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                  data = data.mis.m)

nobs(med.protest.mis.emohealth_chg_cohort.stand)

med.protest.his.emohealth_chg_cohort.stand  <- glmer(protestindex_css ~ protest_tfs + emohealth_chg_cohort + medtreat +
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE),family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                  data = data.his.m)

## Run Mediation summary (exact numbers may vary due to simulations)
med.protest.emohealth_chg_cohort.lis <- mediate(model.m = med.protest.lis.emohealth_chg_cohort.DV, model.y = med.protest.lis.emohealth_chg_cohort.stand, treat = "medtreat", 
                                               mediator = "emohealth_chg_cohort", sims = 500 )
summary(med.protest.emohealth_chg_cohort.lis)

med.protest.emohealth_chg_cohort.mis <- mediate(model.m = med.protest.mis.emohealth_chg_cohort.DV, model.y = med.protest.mis.emohealth_chg_cohort.stand, treat = "medtreat", 
                                               mediator = "emohealth_chg_cohort", sims = 500 )
summary(med.protest.emohealth_chg_cohort.mis)

med.protest.emohealth_chg_cohort.his <- mediate(model.m = med.protest.his.emohealth_chg_cohort.DV, model.y = med.protest.his.emohealth_chg_cohort.stand, treat = "medtreat", 
                                               mediator = "emohealth_chg_cohort", sims = 500 )
summary(med.protest.emohealth_chg_cohort.his)

#################################
# Cohort Motivation to Lead CSS #
#################################

# Only include observations where mediator is observed

csscohort2 <- csscohort[is.na(csscohort$motivationlead_css_cohort) == F,]

# Create datasets 

data.lis.m <- csscohort2[csscohort2$parinc == "Low-Income",]
data.mis.m <- csscohort2[csscohort2$parinc == "Middle-Income",]
data.his.m <- csscohort2[csscohort2$parinc == "High-Income",]

##############
# Passive DV #
##############

# Mediator Models, regressing mediator on school affluence and controls

med.passive.lis.motivationlead_css_cohort.DV  <- lmer(motivationlead_css_cohort ~ medtreat + passive_index_tfs_avg + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.lis.m[!is.na(data.lis.m$passive_index_css_avg),])

med.passive.mis.motivationlead_css_cohort.DV  <- lmer(motivationlead_css_cohort ~ medtreat + passive_index_tfs_avg + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.mis.m[!is.na(data.mis.m$passive_index_css_avg),])

med.passive.his.motivationlead_css_cohort.DV  <- lmer(motivationlead_css_cohort ~ medtreat + passive_index_tfs_avg + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.his.m[!is.na(data.his.m$passive_index_css_avg),])

# Outcome Models, regressing outcome on mediator, school affluence, and controls

med.passive.lis.motivationlead_css_cohort.stand  <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + motivationlead_css_cohort + medtreat +
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.lis.m)

med.passive.mis.motivationlead_css_cohort.stand  <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + motivationlead_css_cohort + medtreat +
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.mis.m)

med.passive.his.motivationlead_css_cohort.stand  <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + motivationlead_css_cohort + medtreat +
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.his.m)

## Run Mediation summary (exact numbers may vary due to simulations)

med.passive.motivationlead_css_cohort.lis <- mediate(model.m = med.passive.lis.motivationlead_css_cohort.DV, model.y = med.passive.lis.motivationlead_css_cohort.stand, treat = "medtreat", 
                                               mediator = "motivationlead_css_cohort", sims = 500 )
summary(med.passive.motivationlead_css_cohort.lis)

med.passive.motivationlead_css_cohort.mis <- mediate(model.m = med.passive.mis.motivationlead_css_cohort.DV, model.y = med.passive.mis.motivationlead_css_cohort.stand, treat = "medtreat", 
                                               mediator = "motivationlead_css_cohort", sims = 500 )
summary(med.passive.motivationlead_css_cohort.mis)

med.passive.motivationlead_css_cohort.his <- mediate(model.m = med.passive.his.motivationlead_css_cohort.DV, model.y = med.passive.his.motivationlead_css_cohort.stand, treat = "medtreat", 
                                               mediator = "motivationlead_css_cohort", sims = 500 )
summary(med.passive.motivationlead_css_cohort.his)

##########
# Voting #
##########

## Mediator Models, regressing mediator on school affluence and controls

med.voteprez2.lis.motivationlead_css_cohort.DV  <- lmer(motivationlead_css_cohort ~ medtreat + polaffairs_tfs + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.lis.m[!is.na(data.lis.m$voteprez2),])

med.voteprez2.mis.motivationlead_css_cohort.DV  <- lmer(motivationlead_css_cohort ~ medtreat + polaffairs_tfs + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.mis.m[!is.na(data.mis.m$voteprez2),])

med.voteprez2.his.motivationlead_css_cohort.DV  <- lmer(motivationlead_css_cohort ~ medtreat + polaffairs_tfs + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.his.m[!is.na(data.his.m$voteprez2),])

## Outcome Models, regressing outcome on mediator, school affluence, and controls

med.voteprez2.lis.motivationlead_css_cohort.stand  <- glmer(voteprez2 ~ polaffairs_tfs + motivationlead_css_cohort + medtreat +
                  polaffairs_tfs +  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE), family = binomial("logit"),control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                  data = data.lis.m)


med.voteprez2.mis.motivationlead_css_cohort.stand  <- glmer(voteprez2 ~ polaffairs_tfs + motivationlead_css_cohort + medtreat +
                  polaffairs_tfs +  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE), family = binomial("logit"),control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                  data = data.mis.m)

med.voteprez2.his.motivationlead_css_cohort.stand  <- glmer(voteprez2 ~ polaffairs_tfs + motivationlead_css_cohort + medtreat +
                  polaffairs_tfs +  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE), family = binomial("logit"),control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                  data = data.his.m)

## Run Mediation summary (exact numbers may vary due to simulations)
med.voteprez2.motivationlead_css_cohort.lis <- mediate(model.m = med.voteprez2.lis.motivationlead_css_cohort.DV, model.y = med.voteprez2.lis.motivationlead_css_cohort.stand, treat = "medtreat", 
                                        mediator = "motivationlead_css_cohort", sims = 500 )
summary(med.voteprez2.motivationlead_css_cohort.lis)

med.voteprez2.motivationlead_css_cohort.mis <- mediate(model.m = med.voteprez2.mis.motivationlead_css_cohort.DV, model.y = med.voteprez2.mis.motivationlead_css_cohort.stand, treat = "medtreat", 
                                        mediator = "motivationlead_css_cohort", sims = 500 )
summary(med.voteprez2.motivationlead_css_cohort.mis)

med.voteprez2.motivationlead_css_cohort.his <- mediate(model.m = med.voteprez2.his.motivationlead_css_cohort.DV, model.y = med.voteprez2.his.motivationlead_css_cohort.stand, treat = "medtreat", 
                                        mediator = "motivationlead_css_cohort", sims = 500 )
summary(med.voteprez2.motivationlead_css_cohort.his)

##############
# Protesting #
##############

## Mediator Models, regressing mediator on school affluence and controls

med.protest.lis.motivationlead_css_cohort.DV  <- lmer(motivationlead_css_cohort ~ medtreat + protest_tfs + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE), data = data.lis.m[!is.na(data.lis.m$protestindex_css),])

med.protest.mis.motivationlead_css_cohort.DV  <- lmer(motivationlead_css_cohort ~ medtreat + protest_tfs + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE), data = data.mis.m[!is.na(data.mis.m$protestindex_css),])

nobs(med.protest.mis.motivationlead_css_cohort.DV)

med.protest.his.motivationlead_css_cohort.DV  <- lmer(motivationlead_css_cohort ~ medtreat + protest_tfs + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE), data = data.his.m[!is.na(data.his.m$protestindex_css),])

## Outcome Models, regressing outcome on mediator, school affluence, and controls

med.protest.lis.motivationlead_css_cohort.stand  <- glmer(protestindex_css ~ protest_tfs + motivationlead_css_cohort + medtreat +
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE),family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                  data = data.lis.m)

med.protest.mis.motivationlead_css_cohort.stand  <- glmer(protestindex_css ~ protest_tfs + motivationlead_css_cohort + medtreat +
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE),family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                  data = data.mis.m)

nobs(med.protest.mis.motivationlead_css_cohort.stand)

med.protest.his.motivationlead_css_cohort.stand  <- glmer(protestindex_css ~ protest_tfs + motivationlead_css_cohort + medtreat +
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE),family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                  data = data.his.m)

## Run Mediation summary (exact numbers may vary due to simulations)
med.protest.motivationlead_css_cohort.lis <- mediate(model.m = med.protest.lis.motivationlead_css_cohort.DV, model.y = med.protest.lis.motivationlead_css_cohort.stand, treat = "medtreat", 
                                               mediator = "motivationlead_css_cohort", sims = 500 )
summary(med.protest.motivationlead_css_cohort.lis)

med.protest.motivationlead_css_cohort.mis <- mediate(model.m = med.protest.mis.motivationlead_css_cohort.DV, model.y = med.protest.mis.motivationlead_css_cohort.stand, treat = "medtreat", 
                                               mediator = "motivationlead_css_cohort", sims = 500 )
summary(med.protest.motivationlead_css_cohort.mis)

med.protest.motivationlead_css_cohort.his <- mediate(model.m = med.protest.his.motivationlead_css_cohort.DV, model.y = med.protest.his.motivationlead_css_cohort.stand, treat = "medtreat", 
                                               mediator = "motivationlead_css_cohort", sims = 500 )
summary(med.protest.motivationlead_css_cohort.his)

#####################################
# Cohort Motivation to Lead TFS-CSS #
#####################################

# Only include observations where mediator is observed

csscohort2 <- csscohort[is.na(csscohort$motivationlead_chg_cohort) == F,]

# Create datasets 

data.lis.m <- csscohort2[csscohort2$parinc == "Low-Income",]
data.mis.m <- csscohort2[csscohort2$parinc == "Middle-Income",]
data.his.m <- csscohort2[csscohort2$parinc == "High-Income",]

##############
# Passive DV #
##############

# Mediator Models, regressing mediator on school affluence and controls

med.passive.lis.motivationlead_chg_cohort.DV  <- lmer(motivationlead_chg_cohort ~ medtreat + passive_index_tfs_avg + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.lis.m[!is.na(data.lis.m$passive_index_css_avg),])

med.passive.mis.motivationlead_chg_cohort.DV  <- lmer(motivationlead_chg_cohort ~ medtreat + passive_index_tfs_avg + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.mis.m[!is.na(data.mis.m$passive_index_css_avg),])

med.passive.his.motivationlead_chg_cohort.DV  <- lmer(motivationlead_chg_cohort ~ medtreat + passive_index_tfs_avg + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.his.m[!is.na(data.his.m$passive_index_css_avg),])

# Outcome Models, regressing outcome on mediator, school affluence, and controls

med.passive.lis.motivationlead_chg_cohort.stand  <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + motivationlead_chg_cohort + medtreat +
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.lis.m)

med.passive.mis.motivationlead_chg_cohort.stand  <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + motivationlead_chg_cohort + medtreat +
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.mis.m)

med.passive.his.motivationlead_chg_cohort.stand  <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + motivationlead_chg_cohort + medtreat +
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.his.m)

## Run Mediation summary (exact numbers may vary due to simulations)

med.passive.motivationlead_chg_cohort.lis <- mediate(model.m = med.passive.lis.motivationlead_chg_cohort.DV, model.y = med.passive.lis.motivationlead_chg_cohort.stand, treat = "medtreat", 
                                               mediator = "motivationlead_chg_cohort", sims = 500 )
summary(med.passive.motivationlead_chg_cohort.lis)

med.passive.motivationlead_chg_cohort.mis <- mediate(model.m = med.passive.mis.motivationlead_chg_cohort.DV, model.y = med.passive.mis.motivationlead_chg_cohort.stand, treat = "medtreat", 
                                               mediator = "motivationlead_chg_cohort", sims = 500 )
summary(med.passive.motivationlead_chg_cohort.mis)

med.passive.motivationlead_chg_cohort.his <- mediate(model.m = med.passive.his.motivationlead_chg_cohort.DV, model.y = med.passive.his.motivationlead_chg_cohort.stand, treat = "medtreat", 
                                               mediator = "motivationlead_chg_cohort", sims = 500 )
summary(med.passive.motivationlead_chg_cohort.his)

##########
# Voting #
##########

## Mediator Models, regressing mediator on school affluence and controls

med.voteprez2.lis.motivationlead_chg_cohort.DV  <- lmer(motivationlead_chg_cohort ~ medtreat + polaffairs_tfs + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.lis.m[!is.na(data.lis.m$voteprez2),])

med.voteprez2.mis.motivationlead_chg_cohort.DV  <- lmer(motivationlead_chg_cohort ~ medtreat + polaffairs_tfs + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.mis.m[!is.na(data.mis.m$voteprez2),])

med.voteprez2.his.motivationlead_chg_cohort.DV  <- lmer(motivationlead_chg_cohort ~ medtreat + polaffairs_tfs + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.his.m[!is.na(data.his.m$voteprez2),])

## Outcome Models, regressing outcome on mediator, school affluence, and controls

med.voteprez2.lis.motivationlead_chg_cohort.stand  <- glmer(voteprez2 ~ polaffairs_tfs + motivationlead_chg_cohort + medtreat +
                  polaffairs_tfs +  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE), family = binomial("logit"),control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                  data = data.lis.m)


med.voteprez2.mis.motivationlead_chg_cohort.stand  <- glmer(voteprez2 ~ polaffairs_tfs + motivationlead_chg_cohort + medtreat +
                  polaffairs_tfs +  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE), family = binomial("logit"),control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                  data = data.mis.m)

med.voteprez2.his.motivationlead_chg_cohort.stand  <- glmer(voteprez2 ~ polaffairs_tfs + motivationlead_chg_cohort + medtreat +
                  polaffairs_tfs +  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE), family = binomial("logit"),control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                  data = data.his.m)

## Run Mediation summary (exact numbers may vary due to simulations)
med.voteprez2.motivationlead_chg_cohort.lis <- mediate(model.m = med.voteprez2.lis.motivationlead_chg_cohort.DV, model.y = med.voteprez2.lis.motivationlead_chg_cohort.stand, treat = "medtreat", 
                                        mediator = "motivationlead_chg_cohort", sims = 500 )
summary(med.voteprez2.motivationlead_chg_cohort.lis)

med.voteprez2.motivationlead_chg_cohort.mis <- mediate(model.m = med.voteprez2.mis.motivationlead_chg_cohort.DV, model.y = med.voteprez2.mis.motivationlead_chg_cohort.stand, treat = "medtreat", 
                                        mediator = "motivationlead_chg_cohort", sims = 500 )
summary(med.voteprez2.motivationlead_chg_cohort.mis)

med.voteprez2.motivationlead_chg_cohort.his <- mediate(model.m = med.voteprez2.his.motivationlead_chg_cohort.DV, model.y = med.voteprez2.his.motivationlead_chg_cohort.stand, treat = "medtreat", 
                                        mediator = "motivationlead_chg_cohort", sims = 500 )
summary(med.voteprez2.motivationlead_chg_cohort.his)

##############
# Protesting #
##############

## Mediator Models, regressing mediator on school affluence and controls

med.protest.lis.motivationlead_chg_cohort.DV  <- lmer(motivationlead_chg_cohort ~ medtreat + protest_tfs + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE), data = data.lis.m[!is.na(data.lis.m$protestindex_css),])

med.protest.mis.motivationlead_chg_cohort.DV  <- lmer(motivationlead_chg_cohort ~ medtreat + protest_tfs + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE), data = data.mis.m[!is.na(data.mis.m$protestindex_css),])

nobs(med.protest.mis.motivationlead_chg_cohort.DV)

med.protest.his.motivationlead_chg_cohort.DV  <- lmer(motivationlead_chg_cohort ~ medtreat + protest_tfs + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE), data = data.his.m[!is.na(data.his.m$protestindex_css),])

## Outcome Models, regressing outcome on mediator, school affluence, and controls

med.protest.lis.motivationlead_chg_cohort.stand  <- glmer(protestindex_css ~ protest_tfs + motivationlead_chg_cohort + medtreat +
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE),family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                  data = data.lis.m)

med.protest.mis.motivationlead_chg_cohort.stand  <- glmer(protestindex_css ~ protest_tfs + motivationlead_chg_cohort + medtreat +
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE),family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                  data = data.mis.m)

nobs(med.protest.mis.motivationlead_chg_cohort.stand)

med.protest.his.motivationlead_chg_cohort.stand  <- glmer(protestindex_css ~ protest_tfs + motivationlead_chg_cohort + medtreat +
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE),family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                  data = data.his.m)

## Run Mediation summary (exact numbers may vary due to simulations)
med.protest.motivationlead_chg_cohort.lis <- mediate(model.m = med.protest.lis.motivationlead_chg_cohort.DV, model.y = med.protest.lis.motivationlead_chg_cohort.stand, treat = "medtreat", 
                                               mediator = "motivationlead_chg_cohort", sims = 500 )
summary(med.protest.motivationlead_chg_cohort.lis)

med.protest.motivationlead_chg_cohort.mis <- mediate(model.m = med.protest.mis.motivationlead_chg_cohort.DV, model.y = med.protest.mis.motivationlead_chg_cohort.stand, treat = "medtreat", 
                                               mediator = "motivationlead_chg_cohort", sims = 500 )
summary(med.protest.motivationlead_chg_cohort.mis)

med.protest.motivationlead_chg_cohort.his <- mediate(model.m = med.protest.his.motivationlead_chg_cohort.DV, model.y = med.protest.his.motivationlead_chg_cohort.stand, treat = "medtreat", 
                                               mediator = "motivationlead_chg_cohort", sims = 500 )
summary(med.protest.motivationlead_chg_cohort.his)

######################
# Academic Mechanism #
######################

###########################
# Academic Competance CSS #
###########################

# Only include observations where mediator is observed

csscohort2 <- csscohort[is.na(csscohort$academcomp_css_cohort) == F,]

# Create datasets 

data.lis.m <- csscohort2[csscohort2$parinc == "Low-Income",]
data.mis.m <- csscohort2[csscohort2$parinc == "Middle-Income",]
data.his.m <- csscohort2[csscohort2$parinc == "High-Income",]

##############
# Passive DV #
##############

# Mediator Models, regressing mediator on school affluence and controls

med.passive.lis.academcomp_css_cohort.DV  <- lmer(academcomp_css_cohort ~ medtreat + passive_index_tfs_avg + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.lis.m[!is.na(data.lis.m$passive_index_css_avg),])

med.passive.mis.academcomp_css_cohort.DV  <- lmer(academcomp_css_cohort ~ medtreat + passive_index_tfs_avg + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.mis.m[!is.na(data.mis.m$passive_index_css_avg),])

med.passive.his.academcomp_css_cohort.DV  <- lmer(academcomp_css_cohort ~ medtreat + passive_index_tfs_avg + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.his.m[!is.na(data.his.m$passive_index_css_avg),])

# Outcome Models, regressing outcome on mediator, school affluence, and controls

med.passive.lis.academcomp_css_cohort.stand  <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + academcomp_css_cohort + medtreat +
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.lis.m)

med.passive.mis.academcomp_css_cohort.stand  <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + academcomp_css_cohort + medtreat +
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.mis.m)

med.passive.his.academcomp_css_cohort.stand  <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + academcomp_css_cohort + medtreat +
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.his.m)

## Run Mediation summary (exact numbers may vary due to simulations)

med.passive.academcomp_css_cohort.lis <- mediate(model.m = med.passive.lis.academcomp_css_cohort.DV, model.y = med.passive.lis.academcomp_css_cohort.stand, treat = "medtreat", 
                                               mediator = "academcomp_css_cohort", sims = 500 )
summary(med.passive.academcomp_css_cohort.lis)

med.passive.academcomp_css_cohort.mis <- mediate(model.m = med.passive.mis.academcomp_css_cohort.DV, model.y = med.passive.mis.academcomp_css_cohort.stand, treat = "medtreat", 
                                               mediator = "academcomp_css_cohort", sims = 500 )
summary(med.passive.academcomp_css_cohort.mis)

med.passive.academcomp_css_cohort.his <- mediate(model.m = med.passive.his.academcomp_css_cohort.DV, model.y = med.passive.his.academcomp_css_cohort.stand, treat = "medtreat", 
                                               mediator = "academcomp_css_cohort", sims = 500 )
summary(med.passive.academcomp_css_cohort.his)

##########
# Voting #
##########

## Mediator Models, regressing mediator on school affluence and controls

med.voteprez2.lis.academcomp_css_cohort.DV  <- lmer(academcomp_css_cohort ~ medtreat + polaffairs_tfs + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.lis.m[!is.na(data.lis.m$voteprez2),])

med.voteprez2.mis.academcomp_css_cohort.DV  <- lmer(academcomp_css_cohort ~ medtreat + polaffairs_tfs + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.mis.m[!is.na(data.mis.m$voteprez2),])

med.voteprez2.his.academcomp_css_cohort.DV  <- lmer(academcomp_css_cohort ~ medtreat + polaffairs_tfs + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.his.m[!is.na(data.his.m$voteprez2),])

## Outcome Models, regressing outcome on mediator, school affluence, and controls

med.voteprez2.lis.academcomp_css_cohort.stand  <- glmer(voteprez2 ~ polaffairs_tfs + academcomp_css_cohort + medtreat +
                  polaffairs_tfs +  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE), family = binomial("logit"),control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                  data = data.lis.m)


med.voteprez2.mis.academcomp_css_cohort.stand  <- glmer(voteprez2 ~ polaffairs_tfs + academcomp_css_cohort + medtreat +
                  polaffairs_tfs +  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE), family = binomial("logit"),control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                  data = data.mis.m)

med.voteprez2.his.academcomp_css_cohort.stand  <- glmer(voteprez2 ~ polaffairs_tfs + academcomp_css_cohort + medtreat +
                  polaffairs_tfs +  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE), family = binomial("logit"),control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                  data = data.his.m)

## Run Mediation summary (exact numbers may vary due to simulations)
med.voteprez2.academcomp_css_cohort.lis <- mediate(model.m = med.voteprez2.lis.academcomp_css_cohort.DV, model.y = med.voteprez2.lis.academcomp_css_cohort.stand, treat = "medtreat", 
                                        mediator = "academcomp_css_cohort", sims = 500 )
summary(med.voteprez2.academcomp_css_cohort.lis)

med.voteprez2.academcomp_css_cohort.mis <- mediate(model.m = med.voteprez2.mis.academcomp_css_cohort.DV, model.y = med.voteprez2.mis.academcomp_css_cohort.stand, treat = "medtreat", 
                                        mediator = "academcomp_css_cohort", sims = 500 )
summary(med.voteprez2.academcomp_css_cohort.mis)

med.voteprez2.academcomp_css_cohort.his <- mediate(model.m = med.voteprez2.his.academcomp_css_cohort.DV, model.y = med.voteprez2.his.academcomp_css_cohort.stand, treat = "medtreat", 
                                        mediator = "academcomp_css_cohort", sims = 500 )
summary(med.voteprez2.academcomp_css_cohort.his)

##############
# Protesting #
##############

## Mediator Models, regressing mediator on school affluence and controls

med.protest.lis.academcomp_css_cohort.DV  <- lmer(academcomp_css_cohort ~ medtreat + protest_tfs + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE), data = data.lis.m[!is.na(data.lis.m$protestindex_css),])

med.protest.mis.academcomp_css_cohort.DV  <- lmer(academcomp_css_cohort ~ medtreat + protest_tfs + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE), data = data.mis.m[!is.na(data.mis.m$protestindex_css),])

nobs(med.protest.mis.academcomp_css_cohort.DV)

med.protest.his.academcomp_css_cohort.DV  <- lmer(academcomp_css_cohort ~ medtreat + protest_tfs + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE), data = data.his.m[!is.na(data.his.m$protestindex_css),])

## Outcome Models, regressing outcome on mediator, school affluence, and controls

med.protest.lis.academcomp_css_cohort.stand  <- glmer(protestindex_css ~ protest_tfs + academcomp_css_cohort + medtreat +
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE),family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                  data = data.lis.m)

med.protest.mis.academcomp_css_cohort.stand  <- glmer(protestindex_css ~ protest_tfs + academcomp_css_cohort + medtreat +
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE),family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                  data = data.mis.m)

nobs(med.protest.mis.academcomp_css_cohort.stand)

med.protest.his.academcomp_css_cohort.stand  <- glmer(protestindex_css ~ protest_tfs + academcomp_css_cohort + medtreat +
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE),family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                  data = data.his.m)

## Run Mediation summary (exact numbers may vary due to simulations)
med.protest.academcomp_css_cohort.lis <- mediate(model.m = med.protest.lis.academcomp_css_cohort.DV, model.y = med.protest.lis.academcomp_css_cohort.stand, treat = "medtreat", 
                                               mediator = "academcomp_css_cohort", sims = 500 )
summary(med.protest.academcomp_css_cohort.lis)

med.protest.academcomp_css_cohort.mis <- mediate(model.m = med.protest.mis.academcomp_css_cohort.DV, model.y = med.protest.mis.academcomp_css_cohort.stand, treat = "medtreat", 
                                               mediator = "academcomp_css_cohort", sims = 500 )
summary(med.protest.academcomp_css_cohort.mis)

med.protest.academcomp_css_cohort.his <- mediate(model.m = med.protest.his.academcomp_css_cohort.DV, model.y = med.protest.his.academcomp_css_cohort.stand, treat = "medtreat", 
                                               mediator = "academcomp_css_cohort", sims = 500 )
summary(med.protest.academcomp_css_cohort.his)

###############################
# Academic Competance TFS-CSS #
###############################

# Only include observations where mediator is observed

csscohort2 <- csscohort[is.na(csscohort$academcomp_chg_cohort) == F,]

# Create datasets 

data.lis.m <- csscohort2[csscohort2$parinc == "Low-Income",]
data.mis.m <- csscohort2[csscohort2$parinc == "Middle-Income",]
data.his.m <- csscohort2[csscohort2$parinc == "High-Income",]

##############
# Passive DV #
##############

# Mediator Models, regressing mediator on school affluence and controls

med.passive.lis.academcomp_chg_cohort.DV  <- lmer(academcomp_chg_cohort ~ medtreat + passive_index_tfs_avg + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.lis.m[!is.na(data.lis.m$passive_index_css_avg),])

med.passive.mis.academcomp_chg_cohort.DV  <- lmer(academcomp_chg_cohort ~ medtreat + passive_index_tfs_avg + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.mis.m[!is.na(data.mis.m$passive_index_css_avg),])

med.passive.his.academcomp_chg_cohort.DV  <- lmer(academcomp_chg_cohort ~ medtreat + passive_index_tfs_avg + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.his.m[!is.na(data.his.m$passive_index_css_avg),])

# Outcome Models, regressing outcome on mediator, school affluence, and controls

med.passive.lis.academcomp_chg_cohort.stand  <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + academcomp_chg_cohort + medtreat +
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.lis.m)

med.passive.mis.academcomp_chg_cohort.stand  <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + academcomp_chg_cohort + medtreat +
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.mis.m)

med.passive.his.academcomp_chg_cohort.stand  <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + academcomp_chg_cohort + medtreat +
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.his.m)

## Run Mediation summary (exact numbers may vary due to simulations)

med.passive.academcomp_chg_cohort.lis <- mediate(model.m = med.passive.lis.academcomp_chg_cohort.DV, model.y = med.passive.lis.academcomp_chg_cohort.stand, treat = "medtreat", 
                                               mediator = "academcomp_chg_cohort", sims = 500 )
summary(med.passive.academcomp_chg_cohort.lis)

med.passive.academcomp_chg_cohort.mis <- mediate(model.m = med.passive.mis.academcomp_chg_cohort.DV, model.y = med.passive.mis.academcomp_chg_cohort.stand, treat = "medtreat", 
                                               mediator = "academcomp_chg_cohort", sims = 500 )
summary(med.passive.academcomp_chg_cohort.mis)

med.passive.academcomp_chg_cohort.his <- mediate(model.m = med.passive.his.academcomp_chg_cohort.DV, model.y = med.passive.his.academcomp_chg_cohort.stand, treat = "medtreat", 
                                               mediator = "academcomp_chg_cohort", sims = 500 )
summary(med.passive.academcomp_chg_cohort.his)

##########
# Voting #
##########

## Mediator Models, regressing mediator on school affluence and controls

med.voteprez2.lis.academcomp_chg_cohort.DV  <- lmer(academcomp_chg_cohort ~ medtreat + polaffairs_tfs + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.lis.m[!is.na(data.lis.m$voteprez2),])

med.voteprez2.mis.academcomp_chg_cohort.DV  <- lmer(academcomp_chg_cohort ~ medtreat + polaffairs_tfs + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.mis.m[!is.na(data.mis.m$voteprez2),])

med.voteprez2.his.academcomp_chg_cohort.DV  <- lmer(academcomp_chg_cohort ~ medtreat + polaffairs_tfs + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.his.m[!is.na(data.his.m$voteprez2),])

## Outcome Models, regressing outcome on mediator, school affluence, and controls

med.voteprez2.lis.academcomp_chg_cohort.stand  <- glmer(voteprez2 ~ polaffairs_tfs + academcomp_chg_cohort + medtreat +
                  polaffairs_tfs +  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE), family = binomial("logit"),control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                  data = data.lis.m)


med.voteprez2.mis.academcomp_chg_cohort.stand  <- glmer(voteprez2 ~ polaffairs_tfs + academcomp_chg_cohort + medtreat +
                  polaffairs_tfs +  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE), family = binomial("logit"),control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                  data = data.mis.m)

med.voteprez2.his.academcomp_chg_cohort.stand  <- glmer(voteprez2 ~ polaffairs_tfs + academcomp_chg_cohort + medtreat +
                  polaffairs_tfs +  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE), family = binomial("logit"),control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                  data = data.his.m)

## Run Mediation summary (exact numbers may vary due to simulations)
med.voteprez2.academcomp_chg_cohort.lis <- mediate(model.m = med.voteprez2.lis.academcomp_chg_cohort.DV, model.y = med.voteprez2.lis.academcomp_chg_cohort.stand, treat = "medtreat", 
                                        mediator = "academcomp_chg_cohort", sims = 500 )
summary(med.voteprez2.academcomp_chg_cohort.lis)

med.voteprez2.academcomp_chg_cohort.mis <- mediate(model.m = med.voteprez2.mis.academcomp_chg_cohort.DV, model.y = med.voteprez2.mis.academcomp_chg_cohort.stand, treat = "medtreat", 
                                        mediator = "academcomp_chg_cohort", sims = 500 )
summary(med.voteprez2.academcomp_chg_cohort.mis)

med.voteprez2.academcomp_chg_cohort.his <- mediate(model.m = med.voteprez2.his.academcomp_chg_cohort.DV, model.y = med.voteprez2.his.academcomp_chg_cohort.stand, treat = "medtreat", 
                                        mediator = "academcomp_chg_cohort", sims = 500 )
summary(med.voteprez2.academcomp_chg_cohort.his)

##############
# Protesting #
##############

## Mediator Models, regressing mediator on school affluence and controls

med.protest.lis.academcomp_chg_cohort.DV  <- lmer(academcomp_chg_cohort ~ medtreat + protest_tfs + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE), data = data.lis.m[!is.na(data.lis.m$protestindex_css),])

med.protest.mis.academcomp_chg_cohort.DV  <- lmer(academcomp_chg_cohort ~ medtreat + protest_tfs + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE), data = data.mis.m[!is.na(data.mis.m$protestindex_css),])

nobs(med.protest.mis.academcomp_chg_cohort.DV)

med.protest.his.academcomp_chg_cohort.DV  <- lmer(academcomp_chg_cohort ~ medtreat + protest_tfs + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE), data = data.his.m[!is.na(data.his.m$protestindex_css),])

## Outcome Models, regressing outcome on mediator, school affluence, and controls

med.protest.lis.academcomp_chg_cohort.stand  <- glmer(protestindex_css ~ protest_tfs + academcomp_chg_cohort + medtreat +
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE),family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                  data = data.lis.m)

med.protest.mis.academcomp_chg_cohort.stand  <- glmer(protestindex_css ~ protest_tfs + academcomp_chg_cohort + medtreat +
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE),family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                  data = data.mis.m)

nobs(med.protest.mis.academcomp_chg_cohort.stand)

med.protest.his.academcomp_chg_cohort.stand  <- glmer(protestindex_css ~ protest_tfs + academcomp_chg_cohort + medtreat +
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE),family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                  data = data.his.m)

## Run Mediation summary (exact numbers may vary due to simulations)
med.protest.academcomp_chg_cohort.lis <- mediate(model.m = med.protest.lis.academcomp_chg_cohort.DV, model.y = med.protest.lis.academcomp_chg_cohort.stand, treat = "medtreat", 
                                               mediator = "academcomp_chg_cohort", sims = 500 )
summary(med.protest.academcomp_chg_cohort.lis)

med.protest.academcomp_chg_cohort.mis <- mediate(model.m = med.protest.mis.academcomp_chg_cohort.DV, model.y = med.protest.mis.academcomp_chg_cohort.stand, treat = "medtreat", 
                                               mediator = "academcomp_chg_cohort", sims = 500 )
summary(med.protest.academcomp_chg_cohort.mis)

med.protest.academcomp_chg_cohort.his <- mediate(model.m = med.protest.his.academcomp_chg_cohort.DV, model.y = med.protest.his.academcomp_chg_cohort.stand, treat = "medtreat", 
                                               mediator = "academcomp_chg_cohort", sims = 500 )
summary(med.protest.academcomp_chg_cohort.his)

####################
# Social Mechanism #
####################

##############################
# Social Self-Confidence CSS #
##############################

# Only include observations where mediator is observed

csscohort2 <- csscohort[is.na(csscohort$soccon_css_cohort) == F,]

# Create datasets 

data.lis.m <- csscohort2[csscohort2$parinc == "Low-Income",]
data.mis.m <- csscohort2[csscohort2$parinc == "Middle-Income",]
data.his.m <- csscohort2[csscohort2$parinc == "High-Income",]

##############
# Passive DV #
##############

# Mediator Models, regressing mediator on school affluence and controls

med.passive.lis.soccon_css_cohort.DV  <- lmer(soccon_css_cohort ~ medtreat + passive_index_tfs_avg + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.lis.m[!is.na(data.lis.m$passive_index_css_avg),])

med.passive.mis.soccon_css_cohort.DV  <- lmer(soccon_css_cohort ~ medtreat + passive_index_tfs_avg + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.mis.m[!is.na(data.mis.m$passive_index_css_avg),])

med.passive.his.soccon_css_cohort.DV  <- lmer(soccon_css_cohort ~ medtreat + passive_index_tfs_avg + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.his.m[!is.na(data.his.m$passive_index_css_avg),])

# Outcome Models, regressing outcome on mediator, school affluence, and controls

med.passive.lis.soccon_css_cohort.stand  <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + soccon_css_cohort + medtreat +
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.lis.m)

med.passive.mis.soccon_css_cohort.stand  <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + soccon_css_cohort + medtreat +
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.mis.m)

med.passive.his.soccon_css_cohort.stand  <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + soccon_css_cohort + medtreat +
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.his.m)

## Run Mediation summary (exact numbers may vary due to simulations)

med.passive.soccon_css_cohort.lis <- mediate(model.m = med.passive.lis.soccon_css_cohort.DV, model.y = med.passive.lis.soccon_css_cohort.stand, treat = "medtreat", 
                                               mediator = "soccon_css_cohort", sims = 500 )
summary(med.passive.soccon_css_cohort.lis)

med.passive.soccon_css_cohort.mis <- mediate(model.m = med.passive.mis.soccon_css_cohort.DV, model.y = med.passive.mis.soccon_css_cohort.stand, treat = "medtreat", 
                                               mediator = "soccon_css_cohort", sims = 500 )
summary(med.passive.soccon_css_cohort.mis)

med.passive.soccon_css_cohort.his <- mediate(model.m = med.passive.his.soccon_css_cohort.DV, model.y = med.passive.his.soccon_css_cohort.stand, treat = "medtreat", 
                                               mediator = "soccon_css_cohort", sims = 500 )
summary(med.passive.soccon_css_cohort.his)

##########
# Voting #
##########

## Mediator Models, regressing mediator on school affluence and controls

med.voteprez2.lis.soccon_css_cohort.DV  <- lmer(soccon_css_cohort ~ medtreat + polaffairs_tfs + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.lis.m[!is.na(data.lis.m$voteprez2),])

med.voteprez2.mis.soccon_css_cohort.DV  <- lmer(soccon_css_cohort ~ medtreat + polaffairs_tfs + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.mis.m[!is.na(data.mis.m$voteprez2),])

med.voteprez2.his.soccon_css_cohort.DV  <- lmer(soccon_css_cohort ~ medtreat + polaffairs_tfs + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.his.m[!is.na(data.his.m$voteprez2),])

## Outcome Models, regressing outcome on mediator, school affluence, and controls

med.voteprez2.lis.soccon_css_cohort.stand  <- glmer(voteprez2 ~ polaffairs_tfs + soccon_css_cohort + medtreat +
                  polaffairs_tfs +  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE), family = binomial("logit"),control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                  data = data.lis.m)


med.voteprez2.mis.soccon_css_cohort.stand  <- glmer(voteprez2 ~ polaffairs_tfs + soccon_css_cohort + medtreat +
                  polaffairs_tfs +  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE), family = binomial("logit"),control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                  data = data.mis.m)

med.voteprez2.his.soccon_css_cohort.stand  <- glmer(voteprez2 ~ polaffairs_tfs + soccon_css_cohort + medtreat +
                  polaffairs_tfs +  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE), family = binomial("logit"),control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                  data = data.his.m)

## Run Mediation summary (exact numbers may vary due to simulations)
med.voteprez2.soccon_css_cohort.lis <- mediate(model.m = med.voteprez2.lis.soccon_css_cohort.DV, model.y = med.voteprez2.lis.soccon_css_cohort.stand, treat = "medtreat", 
                                        mediator = "soccon_css_cohort", sims = 500 )
summary(med.voteprez2.soccon_css_cohort.lis)

med.voteprez2.soccon_css_cohort.mis <- mediate(model.m = med.voteprez2.mis.soccon_css_cohort.DV, model.y = med.voteprez2.mis.soccon_css_cohort.stand, treat = "medtreat", 
                                        mediator = "soccon_css_cohort", sims = 500 )
summary(med.voteprez2.soccon_css_cohort.mis)

med.voteprez2.soccon_css_cohort.his <- mediate(model.m = med.voteprez2.his.soccon_css_cohort.DV, model.y = med.voteprez2.his.soccon_css_cohort.stand, treat = "medtreat", 
                                        mediator = "soccon_css_cohort", sims = 500 )
summary(med.voteprez2.soccon_css_cohort.his)

##############
# Protesting #
##############

## Mediator Models, regressing mediator on school affluence and controls

med.protest.lis.soccon_css_cohort.DV  <- lmer(soccon_css_cohort ~ medtreat + protest_tfs + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE), data = data.lis.m[!is.na(data.lis.m$protestindex_css),])

med.protest.mis.soccon_css_cohort.DV  <- lmer(soccon_css_cohort ~ medtreat + protest_tfs + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE), data = data.mis.m[!is.na(data.mis.m$protestindex_css),])

nobs(med.protest.mis.soccon_css_cohort.DV)

med.protest.his.soccon_css_cohort.DV  <- lmer(soccon_css_cohort ~ medtreat + protest_tfs + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE), data = data.his.m[!is.na(data.his.m$protestindex_css),])

## Outcome Models, regressing outcome on mediator, school affluence, and controls

med.protest.lis.soccon_css_cohort.stand  <- glmer(protestindex_css ~ protest_tfs + soccon_css_cohort + medtreat +
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE),family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                  data = data.lis.m)

med.protest.mis.soccon_css_cohort.stand  <- glmer(protestindex_css ~ protest_tfs + soccon_css_cohort + medtreat +
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE),family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                  data = data.mis.m)

nobs(med.protest.mis.soccon_css_cohort.stand)

med.protest.his.soccon_css_cohort.stand  <- glmer(protestindex_css ~ protest_tfs + soccon_css_cohort + medtreat +
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE),family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                  data = data.his.m)

## Run Mediation summary (exact numbers may vary due to simulations)
med.protest.soccon_css_cohort.lis <- mediate(model.m = med.protest.lis.soccon_css_cohort.DV, model.y = med.protest.lis.soccon_css_cohort.stand, treat = "medtreat", 
                                               mediator = "soccon_css_cohort", sims = 500 )
summary(med.protest.soccon_css_cohort.lis)

med.protest.soccon_css_cohort.mis <- mediate(model.m = med.protest.mis.soccon_css_cohort.DV, model.y = med.protest.mis.soccon_css_cohort.stand, treat = "medtreat", 
                                               mediator = "soccon_css_cohort", sims = 500 )
summary(med.protest.soccon_css_cohort.mis)

med.protest.soccon_css_cohort.his <- mediate(model.m = med.protest.his.soccon_css_cohort.DV, model.y = med.protest.his.soccon_css_cohort.stand, treat = "medtreat", 
                                               mediator = "soccon_css_cohort", sims = 500 )
summary(med.protest.soccon_css_cohort.his)

##################################
# Social Self-Confidence TFS-CSS #
##################################

# Only include observations where mediator is observed

csscohort2 <- csscohort[is.na(csscohort$soccon_chg_cohort) == F,]

# Create datasets 

data.lis.m <- csscohort2[csscohort2$parinc == "Low-Income",]
data.mis.m <- csscohort2[csscohort2$parinc == "Middle-Income",]
data.his.m <- csscohort2[csscohort2$parinc == "High-Income",]

##############
# Passive DV #
##############

# Mediator Models, regressing mediator on school affluence and controls

med.passive.lis.soccon_chg_cohort.DV  <- lmer(soccon_chg_cohort ~ medtreat + passive_index_tfs_avg + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.lis.m[!is.na(data.lis.m$passive_index_css_avg),])

med.passive.mis.soccon_chg_cohort.DV  <- lmer(soccon_chg_cohort ~ medtreat + passive_index_tfs_avg + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.mis.m[!is.na(data.mis.m$passive_index_css_avg),])

med.passive.his.soccon_chg_cohort.DV  <- lmer(soccon_chg_cohort ~ medtreat + passive_index_tfs_avg + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.his.m[!is.na(data.his.m$passive_index_css_avg),])

# Outcome Models, regressing outcome on mediator, school affluence, and controls

med.passive.lis.soccon_chg_cohort.stand  <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + soccon_chg_cohort + medtreat +
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.lis.m)

med.passive.mis.soccon_chg_cohort.stand  <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + soccon_chg_cohort + medtreat +
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.mis.m)

med.passive.his.soccon_chg_cohort.stand  <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + soccon_chg_cohort + medtreat +
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.his.m)

## Run Mediation summary (exact numbers may vary due to simulations)

med.passive.soccon_chg_cohort.lis <- mediate(model.m = med.passive.lis.soccon_chg_cohort.DV, model.y = med.passive.lis.soccon_chg_cohort.stand, treat = "medtreat", 
                                               mediator = "soccon_chg_cohort", sims = 500 )
summary(med.passive.soccon_chg_cohort.lis)

med.passive.soccon_chg_cohort.mis <- mediate(model.m = med.passive.mis.soccon_chg_cohort.DV, model.y = med.passive.mis.soccon_chg_cohort.stand, treat = "medtreat", 
                                               mediator = "soccon_chg_cohort", sims = 500 )
summary(med.passive.soccon_chg_cohort.mis)

med.passive.soccon_chg_cohort.his <- mediate(model.m = med.passive.his.soccon_chg_cohort.DV, model.y = med.passive.his.soccon_chg_cohort.stand, treat = "medtreat", 
                                               mediator = "soccon_chg_cohort", sims = 500 )
summary(med.passive.soccon_chg_cohort.his)

##########
# Voting #
##########

## Mediator Models, regressing mediator on school affluence and controls

med.voteprez2.lis.soccon_chg_cohort.DV  <- lmer(soccon_chg_cohort ~ medtreat + polaffairs_tfs + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.lis.m[!is.na(data.lis.m$voteprez2),])

med.voteprez2.mis.soccon_chg_cohort.DV  <- lmer(soccon_chg_cohort ~ medtreat + polaffairs_tfs + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.mis.m[!is.na(data.mis.m$voteprez2),])

med.voteprez2.his.soccon_chg_cohort.DV  <- lmer(soccon_chg_cohort ~ medtreat + polaffairs_tfs + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.his.m[!is.na(data.his.m$voteprez2),])

## Outcome Models, regressing outcome on mediator, school affluence, and controls

med.voteprez2.lis.soccon_chg_cohort.stand  <- glmer(voteprez2 ~ polaffairs_tfs + soccon_chg_cohort + medtreat +
                  polaffairs_tfs +  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE), family = binomial("logit"),control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                  data = data.lis.m)


med.voteprez2.mis.soccon_chg_cohort.stand  <- glmer(voteprez2 ~ polaffairs_tfs + soccon_chg_cohort + medtreat +
                  polaffairs_tfs +  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE), family = binomial("logit"),control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                  data = data.mis.m)

med.voteprez2.his.soccon_chg_cohort.stand  <- glmer(voteprez2 ~ polaffairs_tfs + soccon_chg_cohort + medtreat +
                  polaffairs_tfs +  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE), family = binomial("logit"),control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                  data = data.his.m)

## Run Mediation summary (exact numbers may vary due to simulations)
med.voteprez2.soccon_chg_cohort.lis <- mediate(model.m = med.voteprez2.lis.soccon_chg_cohort.DV, model.y = med.voteprez2.lis.soccon_chg_cohort.stand, treat = "medtreat", 
                                        mediator = "soccon_chg_cohort", sims = 500 )
summary(med.voteprez2.soccon_chg_cohort.lis)

med.voteprez2.soccon_chg_cohort.mis <- mediate(model.m = med.voteprez2.mis.soccon_chg_cohort.DV, model.y = med.voteprez2.mis.soccon_chg_cohort.stand, treat = "medtreat", 
                                        mediator = "soccon_chg_cohort", sims = 500 )
summary(med.voteprez2.soccon_chg_cohort.mis)

med.voteprez2.soccon_chg_cohort.his <- mediate(model.m = med.voteprez2.his.soccon_chg_cohort.DV, model.y = med.voteprez2.his.soccon_chg_cohort.stand, treat = "medtreat", 
                                        mediator = "soccon_chg_cohort", sims = 500 )
summary(med.voteprez2.soccon_chg_cohort.his)

##############
# Protesting #
##############

## Mediator Models, regressing mediator on school affluence and controls

med.protest.lis.soccon_chg_cohort.DV  <- lmer(soccon_chg_cohort ~ medtreat + protest_tfs + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE), data = data.lis.m[!is.na(data.lis.m$protestindex_css),])

med.protest.mis.soccon_chg_cohort.DV  <- lmer(soccon_chg_cohort ~ medtreat + protest_tfs + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE), data = data.mis.m[!is.na(data.mis.m$protestindex_css),])

nobs(med.protest.mis.soccon_chg_cohort.DV)

med.protest.his.soccon_chg_cohort.DV  <- lmer(soccon_chg_cohort ~ medtreat + protest_tfs + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE), data = data.his.m[!is.na(data.his.m$protestindex_css),])

## Outcome Models, regressing outcome on mediator, school affluence, and controls

med.protest.lis.soccon_chg_cohort.stand  <- glmer(protestindex_css ~ protest_tfs + soccon_chg_cohort + medtreat +
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE),family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                  data = data.lis.m)

med.protest.mis.soccon_chg_cohort.stand  <- glmer(protestindex_css ~ protest_tfs + soccon_chg_cohort + medtreat +
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE),family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                  data = data.mis.m)

nobs(med.protest.mis.soccon_chg_cohort.stand)

med.protest.his.soccon_chg_cohort.stand  <- glmer(protestindex_css ~ protest_tfs + soccon_chg_cohort + medtreat +
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE),family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                  data = data.his.m)

## Run Mediation summary (exact numbers may vary due to simulations)
med.protest.soccon_chg_cohort.lis <- mediate(model.m = med.protest.lis.soccon_chg_cohort.DV, model.y = med.protest.lis.soccon_chg_cohort.stand, treat = "medtreat", 
                                               mediator = "soccon_chg_cohort", sims = 500 )
summary(med.protest.soccon_chg_cohort.lis)

med.protest.soccon_chg_cohort.mis <- mediate(model.m = med.protest.mis.soccon_chg_cohort.DV, model.y = med.protest.mis.soccon_chg_cohort.stand, treat = "medtreat", 
                                               mediator = "soccon_chg_cohort", sims = 500 )
summary(med.protest.soccon_chg_cohort.mis)

med.protest.soccon_chg_cohort.his <- mediate(model.m = med.protest.his.soccon_chg_cohort.DV, model.y = med.protest.his.soccon_chg_cohort.stand, treat = "medtreat", 
                                               mediator = "soccon_chg_cohort", sims = 500 )
summary(med.protest.soccon_chg_cohort.his)


#######################
# Political Mechanism #
#######################

# Only include observations where mediator is observed

csscohort2 <- csscohort[is.na(csscohort$passive_tfs_cohort) == F,]

# Create datasets 

data.lis.m <- csscohort2[csscohort2$parinc == "Low-Income",]
data.mis.m <- csscohort2[csscohort2$parinc == "Middle-Income",]
data.his.m <- csscohort2[csscohort2$parinc == "High-Income",]

##############
# Passive DV #
##############

# Mediator Models, regressing mediator on school affluence and controls

med.passive.lis.passive_tfs_cohort.DV  <- lmer(passive_tfs_cohort ~ medtreat + passive_index_tfs_avg + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.lis.m[!is.na(data.lis.m$passive_index_css_avg),])

med.passive.mis.passive_tfs_cohort.DV  <- lmer(passive_tfs_cohort ~ medtreat + passive_index_tfs_avg + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.mis.m[!is.na(data.mis.m$passive_index_css_avg),])

med.passive.his.passive_tfs_cohort.DV  <- lmer(passive_tfs_cohort ~ medtreat + passive_index_tfs_avg + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.his.m[!is.na(data.his.m$passive_index_css_avg),])

# Outcome Models, regressing outcome on mediator, school affluence, and controls

med.passive.lis.passive_tfs_cohort.stand  <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + passive_tfs_cohort + medtreat +
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.lis.m)

med.passive.mis.passive_tfs_cohort.stand  <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + passive_tfs_cohort + medtreat +
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.mis.m)

med.passive.his.passive_tfs_cohort.stand  <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + passive_tfs_cohort + medtreat +
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.his.m)

## Run Mediation summary (exact numbers may vary due to simulations)

med.passive.passive_tfs_cohort.lis <- mediate(model.m = med.passive.lis.passive_tfs_cohort.DV, model.y = med.passive.lis.passive_tfs_cohort.stand, treat = "medtreat", 
                                               mediator = "passive_tfs_cohort", sims = 500 )
summary(med.passive.passive_tfs_cohort.lis)

med.passive.passive_tfs_cohort.mis <- mediate(model.m = med.passive.mis.passive_tfs_cohort.DV, model.y = med.passive.mis.passive_tfs_cohort.stand, treat = "medtreat", 
                                               mediator = "passive_tfs_cohort", sims = 500 )
summary(med.passive.passive_tfs_cohort.mis)

med.passive.passive_tfs_cohort.his <- mediate(model.m = med.passive.his.passive_tfs_cohort.DV, model.y = med.passive.his.passive_tfs_cohort.stand, treat = "medtreat", 
                                               mediator = "passive_tfs_cohort", sims = 500 )
summary(med.passive.passive_tfs_cohort.his)

##########
# Voting #
##########

## Mediator Models, regressing mediator on school affluence and controls

med.voteprez2.lis.passive_tfs_cohort.DV  <- lmer(passive_tfs_cohort ~ medtreat + polaffairs_tfs + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.lis.m[!is.na(data.lis.m$voteprez2),])

med.voteprez2.mis.passive_tfs_cohort.DV  <- lmer(passive_tfs_cohort ~ medtreat + polaffairs_tfs + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.mis.m[!is.na(data.mis.m$voteprez2),])

med.voteprez2.his.passive_tfs_cohort.DV  <- lmer(passive_tfs_cohort ~ medtreat + polaffairs_tfs + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                  south + factor(YEAR) + (1 | ACERECODE), data = data.his.m[!is.na(data.his.m$voteprez2),])

## Outcome Models, regressing outcome on mediator, school affluence, and controls

med.voteprez2.lis.passive_tfs_cohort.stand  <- glmer(voteprez2 ~ polaffairs_tfs + passive_tfs_cohort + medtreat +
                  polaffairs_tfs +  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE), family = binomial("logit"),control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                  data = data.lis.m)


med.voteprez2.mis.passive_tfs_cohort.stand  <- glmer(voteprez2 ~ polaffairs_tfs + passive_tfs_cohort + medtreat +
                  polaffairs_tfs +  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE), family = binomial("logit"),control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                  data = data.mis.m)

med.voteprez2.his.passive_tfs_cohort.stand  <- glmer(voteprez2 ~ polaffairs_tfs + passive_tfs_cohort + medtreat +
                  polaffairs_tfs +  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE), family = binomial("logit"),control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                  data = data.his.m)

## Run Mediation summary (exact numbers may vary due to simulations)
med.voteprez2.passive_tfs_cohort.lis <- mediate(model.m = med.voteprez2.lis.passive_tfs_cohort.DV, model.y = med.voteprez2.lis.passive_tfs_cohort.stand, treat = "medtreat", 
                                        mediator = "passive_tfs_cohort", sims = 500 )
summary(med.voteprez2.passive_tfs_cohort.lis)

med.voteprez2.passive_tfs_cohort.mis <- mediate(model.m = med.voteprez2.mis.passive_tfs_cohort.DV, model.y = med.voteprez2.mis.passive_tfs_cohort.stand, treat = "medtreat", 
                                        mediator = "passive_tfs_cohort", sims = 500 )
summary(med.voteprez2.passive_tfs_cohort.mis)

med.voteprez2.passive_tfs_cohort.his <- mediate(model.m = med.voteprez2.his.passive_tfs_cohort.DV, model.y = med.voteprez2.his.passive_tfs_cohort.stand, treat = "medtreat", 
                                        mediator = "passive_tfs_cohort", sims = 500 )
summary(med.voteprez2.passive_tfs_cohort.his)

##############
# Protesting #
##############

## Mediator Models, regressing mediator on school affluence and controls

med.protest.lis.passive_tfs_cohort.DV  <- lmer(passive_tfs_cohort ~ medtreat + protest_tfs + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE), data = data.lis.m[!is.na(data.lis.m$protestindex_css),])

med.protest.mis.passive_tfs_cohort.DV  <- lmer(passive_tfs_cohort ~ medtreat + protest_tfs + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE), data = data.mis.m[!is.na(data.mis.m$protestindex_css),])

nobs(med.protest.mis.passive_tfs_cohort.DV)

med.protest.his.passive_tfs_cohort.DV  <- lmer(passive_tfs_cohort ~ medtreat + protest_tfs + 
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE), data = data.his.m[!is.na(data.his.m$protestindex_css),])

## Outcome Models, regressing outcome on mediator, school affluence, and controls

med.protest.lis.passive_tfs_cohort.stand  <- glmer(protestindex_css ~ protest_tfs + passive_tfs_cohort + medtreat +
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE),family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                  data = data.lis.m)

med.protest.mis.passive_tfs_cohort.stand  <- glmer(protestindex_css ~ protest_tfs + passive_tfs_cohort + medtreat +
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE),family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                  data = data.mis.m)

nobs(med.protest.mis.passive_tfs_cohort.stand)

med.protest.his.passive_tfs_cohort.stand  <- glmer(protestindex_css ~ protest_tfs + passive_tfs_cohort + medtreat +
                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                  catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                  hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                  age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                  makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                  (1 | ACERECODE),family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                  data = data.his.m)

## Run Mediation summary (exact numbers may vary due to simulations)
med.protest.passive_tfs_cohort.lis <- mediate(model.m = med.protest.lis.passive_tfs_cohort.DV, model.y = med.protest.lis.passive_tfs_cohort.stand, treat = "medtreat", 
                                               mediator = "passive_tfs_cohort", sims = 500 )
summary(med.protest.passive_tfs_cohort.lis)

med.protest.passive_tfs_cohort.mis <- mediate(model.m = med.protest.mis.passive_tfs_cohort.DV, model.y = med.protest.mis.passive_tfs_cohort.stand, treat = "medtreat", 
                                               mediator = "passive_tfs_cohort", sims = 500 )
summary(med.protest.passive_tfs_cohort.mis)

med.protest.passive_tfs_cohort.his <- mediate(model.m = med.protest.his.passive_tfs_cohort.DV, model.y = med.protest.his.passive_tfs_cohort.stand, treat = "medtreat", 
                                               mediator = "passive_tfs_cohort", sims = 500 )
summary(med.protest.passive_tfs_cohort.his)

#####################
# Appendix Figure 4 #
#####################

#########################
# Passive participation #
#########################

passive.lis.NC <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + factor(affcat) + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), data = data.lis)  

passive.mis.NC <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + factor(affcat) + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), data = data.mis)

passive.his.NC <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + factor(affcat) + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), data = data.his)

modelvars <- c("passive_index_css_avg", "passive_index_tfs_avg", "affcat", "YEAR", "ACERECODE", "ace_year")

csscohort2 <- csscohort[complete.cases(csscohort[,modelvars]),]

data.lis.NC.temp <- csscohort2[csscohort2$parinc == "Low-Income",]
data.mis.NC.temp  <- csscohort2[csscohort2$parinc == "Middle-Income",]
data.his.NC.temp  <- csscohort2[csscohort2$parinc == "High-Income",]

passive.lis.NC.null.p <- summary(passive.lis.NC)$coefficients["factor(affcat)5",5] 

data.lis.NC.temp$affcat <- 1
passive.lis.NC.lis.NC.1 <- mean(predict(passive.lis.NC, data.lis.NC.temp, re.form=NULL)) 
data.lis.NC.temp$affcat <- 5
passive.lis.NC.lis.NC.5 <- mean(predict(passive.lis.NC, data.lis.NC.temp, re.form=NULL)) 
passive.lis.NC.null.eff <- passive.lis.NC.lis.NC.5 - passive.lis.NC.lis.NC.1

passive.mis.NC.null.p <- summary(passive.mis.NC)$coefficients["factor(affcat)5",5] 

data.mis.NC.temp$affcat <- 1
passive.mis.NC.lis.NC.1 <- mean(predict(passive.mis.NC, data.mis.NC.temp, re.form=NULL)) 
data.mis.NC.temp$affcat <- 5
passive.mis.NC.lis.NC.5 <- mean(predict(passive.mis.NC, data.mis.NC.temp, re.form=NULL)) 
passive.mis.NC.null.eff <- passive.mis.NC.lis.NC.5 - passive.mis.NC.lis.NC.1

passive.his.NC.null.p <- summary(passive.his.NC)$coefficients["factor(affcat)5",5] 

data.his.NC.temp$affcat <- 1
passive.his.NC.lis.NC.1 <- mean(predict(passive.his.NC, data.his.NC.temp, re.form=NULL)) 
data.his.NC.temp$affcat <- 5
passive.his.NC.lis.NC.5 <- mean(predict(passive.his.NC, data.his.NC.temp, re.form=NULL)) 
passive.his.NC.null.eff <- passive.his.NC.lis.NC.5 - passive.his.NC.lis.NC.1

##########
# Voting #
##########

voteprez2.lis.NC <- glmer(voteprez2 ~ polaffairs_tfs + factor(affcat) + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"),
                          control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

voteprez2.mis.NC <- glmer(voteprez2 ~ polaffairs_tfs + factor(affcat) + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"),
                          control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.mis)

voteprez2.his.NC <- glmer(voteprez2 ~ polaffairs_tfs + factor(affcat) + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"),
                          control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.his)

modelvars <- c("voteprez2", "polaffairs_tfs", "affcat", "YEAR", "ACERECODE", "ace_year")

csscohort2 <- csscohort[complete.cases(csscohort[,modelvars]),]

data.lis.NC.temp <- csscohort2[csscohort2$parinc == "Low-Income",]
data.mis.NC.temp  <- csscohort2[csscohort2$parinc == "Middle-Income",]
data.his.NC.temp  <- csscohort2[csscohort2$parinc == "High-Income",]

voteprez2.lis.NC.null.p <- summary(voteprez2.lis.NC)$coefficients["factor(affcat)5",4] 

data.lis.NC.temp$affcat <- 1
voteprez2.lis.NC.lis.NC.1 <- mean(predict(voteprez2.lis.NC, data.lis.NC.temp, re.form=NULL, type = "response")) 
data.lis.NC.temp$affcat <- 5
voteprez2.lis.NC.lis.NC.5 <- mean(predict(voteprez2.lis.NC, data.lis.NC.temp, re.form=NULL, type = "response")) 
voteprez2.lis.NC.null.eff <- voteprez2.lis.NC.lis.NC.5 - voteprez2.lis.NC.lis.NC.1

voteprez2.mis.NC.null.p <- summary(voteprez2.mis.NC)$coefficients["factor(affcat)5",4] 

data.mis.NC.temp$affcat <- 1
voteprez2.mis.NC.lis.NC.1 <- mean(predict(voteprez2.mis.NC, data.mis.NC.temp, re.form=NULL, type = "response")) 
data.mis.NC.temp$affcat <- 5
voteprez2.mis.NC.lis.NC.5 <- mean(predict(voteprez2.mis.NC, data.mis.NC.temp, re.form=NULL, type = "response")) 
voteprez2.mis.NC.null.eff <- voteprez2.mis.NC.lis.NC.5 - voteprez2.mis.NC.lis.NC.1

voteprez2.his.NC.null.p <- summary(voteprez2.his.NC)$coefficients["factor(affcat)5",4] 

data.his.NC.temp$affcat <- 1
voteprez2.his.NC.lis.NC.1 <- mean(predict(voteprez2.his.NC, data.his.NC.temp, re.form=NULL, type = "response")) 
data.his.NC.temp$affcat <- 5
voteprez2.his.NC.lis.NC.5 <- mean(predict(voteprez2.his.NC, data.his.NC.temp, re.form=NULL, type = "response")) 
voteprez2.his.NC.null.eff <- voteprez2.his.NC.lis.NC.5 - voteprez2.his.NC.lis.NC.1

###############
# Campaigning #
###############

campaign.lis.NC <- glmer(campaign_css ~ campaign_tfs + factor(affcat) + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"),
                         control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

campaign.mis.NC <- glmer(campaign_css ~ campaign_tfs + factor(affcat) + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"),
                         control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.mis)

campaign.his.NC <- glmer(campaign_css ~ campaign_tfs + factor(affcat) + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"),
                         control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.his)

modelvars <- c("campaign_css", "campaign_tfs", "affcat",  "YEAR", "ACERECODE", "ace_year")

csscohort2 <- csscohort[complete.cases(csscohort[,modelvars]),]

data.lis.NC.temp <- csscohort2[csscohort2$parinc == "Low-Income",]
data.mis.NC.temp  <- csscohort2[csscohort2$parinc == "Middle-Income",]
data.his.NC.temp  <- csscohort2[csscohort2$parinc == "High-Income",]

campaign.lis.NC.null.p <- summary(campaign.lis.NC)$coefficients["factor(affcat)5",4] 

data.lis.NC.temp$affcat <- 1
campaign.lis.NC.lis.NC.1 <- mean(predict(campaign.lis.NC, data.lis.NC.temp, re.form=NULL, type = "response")) 
data.lis.NC.temp$affcat <- 5
campaign.lis.NC.lis.NC.5 <- mean(predict(campaign.lis.NC, data.lis.NC.temp, re.form=NULL, type = "response")) 
campaign.lis.NC.null.eff <- campaign.lis.NC.lis.NC.5 - campaign.lis.NC.lis.NC.1

campaign.mis.NC.null.p <- summary(campaign.mis.NC)$coefficients["factor(affcat)5",4] 

data.mis.NC.temp$affcat <- 1
campaign.mis.NC.lis.NC.1 <- mean(predict(campaign.mis.NC, data.mis.NC.temp, re.form=NULL, type = "response")) 
data.mis.NC.temp$affcat <- 5
campaign.mis.NC.lis.NC.5 <- mean(predict(campaign.mis.NC, data.mis.NC.temp, re.form=NULL, type = "response")) 
campaign.mis.NC.null.eff <- campaign.mis.NC.lis.NC.5 - campaign.mis.NC.lis.NC.1

campaign.his.NC.null.p <- summary(campaign.his.NC)$coefficients["factor(affcat)5",4] 

data.his.NC.temp$affcat <- 1
campaign.his.NC.lis.NC.1 <- mean(predict(campaign.his.NC, data.his.NC.temp, re.form=NULL, type = "response")) 
data.his.NC.temp$affcat <- 5
campaign.his.NC.lis.NC.5 <- mean(predict(campaign.his.NC, data.his.NC.temp, re.form=NULL, type = "response")) 
campaign.his.NC.null.eff <- campaign.his.NC.lis.NC.5 - campaign.his.NC.lis.NC.1

#############################
# Elected to Student Office #
#############################

elected.lis.NC <- glmer(elected01_gov ~ commlead_tfs + factor(affcat) + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"),
                        control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

elected.mis.NC <- glmer(elected01_gov ~ commlead_tfs + factor(affcat) + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"),
                        control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.mis)

elected.his.NC <- glmer(elected01_gov ~ commlead_tfs + factor(affcat) + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"),
                        control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.his)

modelvars <- c("elected01_gov", "commlead_tfs", "affcat",  "YEAR", "ACERECODE", "ace_year")

csscohort2 <- csscohort[complete.cases(csscohort[,modelvars]),]

data.lis.NC.temp <- csscohort2[csscohort2$parinc == "Low-Income",]
data.mis.NC.temp  <- csscohort2[csscohort2$parinc == "Middle-Income",]
data.his.NC.temp  <- csscohort2[csscohort2$parinc == "High-Income",]

elected.lis.NC.null.p <- summary(elected.lis.NC)$coefficients["factor(affcat)5",4] 

data.lis.NC.temp$affcat <- 1
elected.lis.NC.lis.NC.1 <- mean(predict(elected.lis.NC, data.lis.NC.temp, re.form=NULL, type = "response")) 
data.lis.NC.temp$affcat <- 5
elected.lis.NC.lis.NC.5 <- mean(predict(elected.lis.NC, data.lis.NC.temp, re.form=NULL, type = "response")) 
elected.lis.NC.null.eff <- elected.lis.NC.lis.NC.5 - elected.lis.NC.lis.NC.1

elected.mis.NC.null.p <- summary(elected.mis.NC)$coefficients["factor(affcat)5",4] 

data.mis.NC.temp$affcat <- 1
elected.mis.NC.lis.NC.1 <- mean(predict(elected.mis.NC, data.mis.NC.temp, re.form=NULL, type = "response")) 
data.mis.NC.temp$affcat <- 5
elected.mis.NC.lis.NC.5 <- mean(predict(elected.mis.NC, data.mis.NC.temp, re.form=NULL, type = "response")) 
elected.mis.NC.null.eff <- elected.mis.NC.lis.NC.5 - elected.mis.NC.lis.NC.1

elected.his.NC.null.p <- summary(elected.his.NC)$coefficients["factor(affcat)5",4] 

data.his.NC.temp$affcat <- 1
elected.his.NC.lis.NC.1 <- mean(predict(elected.his.NC, data.his.NC.temp, re.form=NULL, type = "response")) 
data.his.NC.temp$affcat <- 5
elected.his.NC.lis.NC.5 <- mean(predict(elected.his.NC, data.his.NC.temp, re.form=NULL, type = "response")) 
elected.his.NC.null.eff <- elected.his.NC.lis.NC.5 - elected.his.NC.lis.NC.1

##################################
# Leader of Student Organization #
##################################

orglead.lis.NC <- glmer(orglead01 ~ commlead_tfs + factor(affcat) + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"),
                        control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)


orglead.mis.NC <- glmer(orglead01 ~ commlead_tfs + factor(affcat) + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"),
                        control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.mis)

orglead.his.NC <- glmer(orglead01 ~ commlead_tfs + factor(affcat) + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"),
                        control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.his)

modelvars <- c("orglead01", "commlead_tfs", "affcat", "YEAR", "ACERECODE", "ace_year")

csscohort2 <- csscohort[complete.cases(csscohort[,modelvars]),]

data.lis.NC.temp <- csscohort2[csscohort2$parinc == "Low-Income",]
data.mis.NC.temp  <- csscohort2[csscohort2$parinc == "Middle-Income",]
data.his.NC.temp  <- csscohort2[csscohort2$parinc == "High-Income",]

orglead.lis.NC.null.p <- summary(orglead.lis.NC)$coefficients["factor(affcat)5",4] 

data.lis.NC.temp$affcat <- 1
orglead.lis.NC.lis.NC.1 <- mean(predict(orglead.lis.NC, data.lis.NC.temp, re.form=NULL, type = "response")) 
data.lis.NC.temp$affcat <- 5
orglead.lis.NC.lis.NC.5 <- mean(predict(orglead.lis.NC, data.lis.NC.temp, re.form=NULL, type = "response")) 
orglead.lis.NC.null.eff <- orglead.lis.NC.lis.NC.5 - orglead.lis.NC.lis.NC.1

orglead.mis.NC.null.p <- summary(orglead.mis.NC)$coefficients["factor(affcat)5",4] 

data.mis.NC.temp$affcat <- 1
orglead.mis.NC.lis.NC.1 <- mean(predict(orglead.mis.NC, data.mis.NC.temp, re.form=NULL, type = "response")) 
data.mis.NC.temp$affcat <- 5
orglead.mis.NC.lis.NC.5 <- mean(predict(orglead.mis.NC, data.mis.NC.temp, re.form=NULL, type = "response")) 
orglead.mis.NC.null.eff <- orglead.mis.NC.lis.NC.5 - orglead.mis.NC.lis.NC.1

orglead.his.NC.null.p <- summary(orglead.his.NC)$coefficients["factor(affcat)5",4] 

data.his.NC.temp$affcat <- 1
orglead.his.NC.lis.NC.1 <- mean(predict(orglead.his.NC, data.his.NC.temp, re.form=NULL, type = "response")) 
data.his.NC.temp$affcat <- 5
orglead.his.NC.lis.NC.5 <- mean(predict(orglead.his.NC, data.his.NC.temp, re.form=NULL, type = "response")) 
orglead.his.NC.null.eff <- orglead.his.NC.lis.NC.5 - orglead.his.NC.lis.NC.1

########################################
# Protest Index 
#########################################

protest.lis.NC <- glmer(protestindex_css ~ protest_tfs + factor(affcat) + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"),
                        control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

protest.mis.NC <- glmer(protestindex_css ~ protest_tfs + factor(affcat) + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"),
                        control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.mis)

protest.his.NC <- glmer(protestindex_css ~ protest_tfs + factor(affcat) + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"),
                        control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.his)

modelvars <- c("protestindex_css", "protest_tfs", "affcat", "YEAR", "ACERECODE", "ace_year")

csscohort2 <- csscohort[complete.cases(csscohort[,modelvars]),]

data.lis.NC.temp <- csscohort2[csscohort2$parinc == "Low-Income",]
data.mis.NC.temp  <- csscohort2[csscohort2$parinc == "Middle-Income",]
data.his.NC.temp  <- csscohort2[csscohort2$parinc == "High-Income",]

protest.lis.NC.null.p <- summary(protest.lis.NC)$coefficients["factor(affcat)5",4] 

data.lis.NC.temp$affcat <- 1
protest.lis.NC.lis.NC.1 <- mean(predict(protest.lis.NC, data.lis.NC.temp, re.form=NULL, type = "response")) 
data.lis.NC.temp$affcat <- 5
protest.lis.NC.lis.NC.5 <- mean(predict(protest.lis.NC, data.lis.NC.temp, re.form=NULL, type = "response")) 
protest.lis.NC.null.eff <- protest.lis.NC.lis.NC.5 - protest.lis.NC.lis.NC.1

protest.mis.NC.null.p <- summary(protest.mis.NC)$coefficients["factor(affcat)5",4] 

data.mis.NC.temp$affcat <- 1
protest.mis.NC.lis.NC.1 <- mean(predict(protest.mis.NC, data.mis.NC.temp, re.form=NULL, type = "response")) 
data.mis.NC.temp$affcat <- 5
protest.mis.NC.lis.NC.5 <- mean(predict(protest.mis.NC, data.mis.NC.temp, re.form=NULL, type = "response")) 
protest.mis.NC.null.eff <- protest.mis.NC.lis.NC.5 - protest.mis.NC.lis.NC.1

protest.his.NC.null.p <- summary(protest.his.NC)$coefficients["factor(affcat)5",4] 

data.his.NC.temp$affcat <- 1
protest.his.NC.lis.NC.1 <- mean(predict(protest.his.NC, data.his.NC.temp, re.form=NULL, type = "response")) 
data.his.NC.temp$affcat <- 5
protest.his.NC.lis.NC.5 <- mean(predict(protest.his.NC, data.his.NC.temp, re.form=NULL, type = "response")) 
protest.his.NC.null.eff <- protest.his.NC.lis.NC.5 - protest.his.NC.lis.NC.1

#################################
# Create Predicted Effects Plot #
#################################

data = data.frame (variable = c("Lead Student Organization", "Lead Student Organization", "Lead Student Organization",
                                "Protest Involvement", "Protest Involvement", "Protest Involvement",
                                 "Passive Engagement Index", "Passive Engagement Index", "Passive Engagement Index",
                                 "Vote in National Election", "Vote in National Election", "Vote in National Election",
                                 "Participate in Campaign", "Participate in Campaign", "Participate in Campaign",
                                 "Participate in Student Government", "Participate in Student Government", "Participate in Student Government"),
                    parinc= c("Low",
                              "Middle",
                              "High"),
                    effect = c(orglead.lis.NC.null.eff, orglead.mis.NC.null.eff, orglead.his.NC.null.eff,
                               protest.lis.NC.null.eff, protest.mis.NC.null.eff, protest.his.NC.null.eff,
                               passive.lis.NC.null.eff, passive.mis.NC.null.eff, passive.his.NC.null.eff,
                               voteprez2.lis.NC.null.eff, voteprez2.mis.NC.null.eff, voteprez2.his.NC.null.eff,
                               campaign.lis.NC.null.eff, campaign.mis.NC.null.eff, campaign.his.NC.null.eff,
                               elected.lis.NC.null.eff, elected.mis.NC.null.eff, elected.his.NC.null.eff ),
                    sig = c(orglead.lis.NC.null.p, orglead.mis.NC.null.p, orglead.his.NC.null.p,
                            protest.lis.NC.null.p, protest.mis.NC.null.p, protest.his.NC.null.p,
                            passive.lis.NC.null.p, passive.mis.NC.null.p, passive.his.NC.null.p,
                            voteprez2.lis.NC.null.p, voteprez2.mis.NC.null.p, voteprez2.his.NC.null.p,
                            campaign.lis.NC.null.p, campaign.mis.NC.null.p, campaign.his.NC.null.p,
                            elected.lis.NC.null.p, elected.mis.NC.null.p, elected.his.NC.null.p)) 


data$sig <- ifelse(data$sig >= .05, "n.s.",
                   ifelse(data$sig < .05 &
                            data$sig >= .01, "*",
                          ifelse(data$sig < .01 &
                                   data$sig >= .001, "**",
                                 ifelse(data$sig < .001, "***", NA))))


data$variable <- factor(data$variable, levels = c("Lead Student Organization",
                                                  "Protest Involvement",
                                                  "Passive Engagement Index",
                                                  "Vote in National Election",
                                                  "Participate in Campaign",
                                                  "Participate in Student Government" ))

p1<- ggplot(data[1:3,], aes(x=parinc, y=effect*100, fill=parinc)) +
  facet_grid(.~variable) +
  geom_bar(stat="identity") +
  ylab("Percentage Point Effect") +
  guides(fill=FALSE) +
  theme_bw() +
  theme(text = element_text(size=12, face="bold"), axis.title.x=element_blank()) +
  geom_hline(yintercept=0, linetype = "dashed") +
  scale_y_continuous(limits=c(-05, 20)) +
  geom_text(aes(x=parinc, y=ifelse(sig=="n.s.", 1.5, .5), 
                label=sig), 
            position = position_dodge(width=1))

p2<-ggplot(data[4:6,], aes(x=parinc, y=effect*100, fill=parinc)) +
  facet_grid(.~variable) +
  geom_bar(stat="identity") +
  guides(fill=FALSE) +
  theme_bw() +
  theme(text = element_text(size=12, face="bold"), axis.title.y=element_blank(), axis.title.x=element_blank()) +
  geom_hline(yintercept=0, linetype = "dashed") +
  scale_y_continuous(limits=c(-2.5, 10), breaks=c(0, 5, 10)) +
  geom_text(aes(x=parinc, y=ifelse(sig=="n.s.", .5, .3), 
                label=sig), 
            position = position_dodge(width=1))

p3<-ggplot(data[7:9,], aes(x=parinc, y=effect*100, fill=parinc)) +
  facet_grid(.~variable) +
  geom_bar(stat="identity") +
  guides(fill=FALSE) +
  theme_bw() +
  theme(text = element_text(size=12, face="bold"), axis.title.y=element_blank(), axis.title.x=element_blank()) +
  geom_hline(yintercept=0, linetype = "dashed") +
  scale_y_continuous(limits=c(-2.5, 10), breaks=c(0, 5, 10)) +
  geom_text(aes(x=parinc, y=ifelse(sig=="n.s.", .4, .3), 
                label=sig), 
            position = position_dodge(width=1))

p4<-ggplot(data[10:12,], aes(x=parinc, y=effect*100, fill=parinc)) +
  facet_grid(.~variable) +
  geom_bar(stat="identity") +
  ylab("Percentage Point Effect") +
  guides(fill=FALSE) +
  theme_bw() +
  theme(text = element_text(size=12, face="bold"), axis.title.x=element_blank()) +
  geom_hline(yintercept=0, linetype = "dashed") +
  scale_y_continuous(limits=c(-5, 10)) +
  geom_text(aes(x=parinc, y=ifelse(sig=="n.s.", .6, .4), 
                label=sig), 
            position = position_dodge(width=1))

p5<-ggplot(data[13:15,], aes(x=parinc, y=effect*100, fill=parinc)) +
  facet_grid(.~variable) +
  geom_bar(stat="identity") +
  guides(fill=FALSE) +
  theme_bw() +
  theme(text = element_text(size=12, face="bold"), axis.title.y=element_blank(), axis.title.x=element_blank()) +
  geom_hline(yintercept=0, linetype = "dashed") +
  scale_y_continuous(limits=c(-5, 10)) +
  geom_text(aes(x=parinc, y=ifelse(sig=="n.s.", 0.6, .4), 
                label=sig), 
            position = position_dodge(width=1))

p6<-ggplot(data[16:18,], aes(x=parinc, y=effect*100, fill=parinc)) +
  facet_grid(.~variable) +
  geom_bar(stat="identity") +
  guides(fill=FALSE) +
  theme_bw() +
  theme(text = element_text(size=12, face="bold"), axis.title.y=element_blank(), axis.title.x=element_blank()) +
  geom_hline(yintercept=0, linetype = "dashed") +
  scale_y_continuous(limits=c(-5, 10)) +
  geom_text(aes(x=parinc, y=ifelse(sig=="n.s.", .6, .5), 
                label=sig), 
            position = position_dodge(width=1))

grid.arrange(p1, p2, p3, p4, p5, p6, nrow=2)

#####################
# Appendix Figure 5 # 
#####################

#######################################
## Political Interest Subset Analysis #
#######################################

cor(data.lis$affper, data.lis$polaffairs_tfs, use = "complete.obs")

table(data.lis$GOAL18_TFS)
table(data.lis$GOAL18_TFS)/sum(table(data.lis$GOAL18_TFS))

mean(ifelse(data.lis$GOAL18_TFS == 3 | data.lis$GOAL18_TFS == 4, 1, 0), na.rm = T)
sd(ifelse(data.lis$GOAL18_TFS == 3 | data.lis$GOAL18_TFS == 4, 1, 0), na.rm = T)

mean(ifelse(csscohort$GOAL18_TFS == 3 | csscohort$GOAL18_TFS == 4, 1, 0), na.rm = T)
sd(ifelse(csscohort$GOAL18_TFS == 3 | csscohort$GOAL18_TFS == 4, 1, 0), na.rm = T)

################# 
# Not Important #
#################

polsub1.df <- data.lis[data.lis$GOAL18_TFS == 1 & !is.na(data.lis$GOAL18_TFS),]

# Models

passive.lis.polsub1.pa <- lmer(passive_index_css_avg ~ factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                                 evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                                 hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                                 age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                                 largesb + public + college + neast + south + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), data = polsub1.df) 
summary(passive.lis.polsub1.pa)

passive.re.lis.full.coefs.polsub1.pa <- data.frame(coef(summary(passive.lis.polsub1.pa)))
passive.re.lis.full.coefs.polsub1.pa$p.z <- 2 * (1 - pnorm(abs(passive.re.lis.full.coefs.polsub1.pa$t.value)))
passive.re.lis.full.coefs.polsub1.pa$p.z

modelvars <- c("passive_index_css_avg", "affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black", "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs", "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south", "YEAR", "ACERECODE", "ace_year")

data.lis.polsub1.pa.temp <- polsub1.df[complete.cases(polsub1.df[,modelvars]),]
nrow(data.lis.polsub1.pa.temp)

passive.lis.polsub1.pa.p <- summary(passive.lis.polsub1.pa)$coefficients["factor(affcat)5",5] 

data.lis.polsub1.pa.temp$affcat <- 1
passive.lis.polsub1.pa.lis.1 <- mean(predict(passive.lis.polsub1.pa, data.lis.polsub1.pa.temp, re.form=NULL)) 
data.lis.polsub1.pa.temp$affcat <- 5
passive.lis.polsub1.pa.lis.5 <- mean(predict(passive.lis.polsub1.pa, data.lis.polsub1.pa.temp, re.form=NULL)) 
passive.lis.polsub1.pa.eff <- passive.lis.polsub1.pa.lis.5 - passive.lis.polsub1.pa.lis.1
passive.lis.polsub1.pa.eff

voteprez2.lis.polsub1.pa <- glmer(voteprez2 ~ factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                                    hihispanicper + hiothraceper + hijewishper+ hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                                    socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                                    factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = polsub1.df) 
summary(voteprez2.lis.polsub1.pa)

modelvars <- c("voteprez2", "affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black", "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs", "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south", "YEAR", "ACERECODE", "ace_year")

data.lis.polsub1.pa.temp <- polsub1.df[complete.cases(polsub1.df[,modelvars]),]
nrow(data.lis.polsub1.pa.temp)

voteprez2.lis.polsub1.pa.p <- summary(voteprez2.lis.polsub1.pa)$coefficients["factor(affcat)5",4] 

data.lis.polsub1.pa.temp$affcat <- 1
voteprez2.lis.polsub1.pa.lis.1 <- mean(predict(voteprez2.lis.polsub1.pa, data.lis.polsub1.pa.temp, re.form=NULL, type = "response")) 
data.lis.polsub1.pa.temp$affcat <- 5
voteprez2.lis.polsub1.pa.lis.5 <- mean(predict(voteprez2.lis.polsub1.pa, data.lis.polsub1.pa.temp, re.form=NULL, type = "response")) 
voteprez2.lis.polsub1.pa.eff <- voteprez2.lis.polsub1.pa.lis.5 - voteprez2.lis.polsub1.pa.lis.1
voteprez2.lis.polsub1.pa.eff

campaign.lis.polsub1.pa <- glmer(campaign_css ~ factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                                   hihispanicper + hiothraceper + hijewishper+ hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                                   socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                                   factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = polsub1.df) 
summary(campaign.lis.polsub1.pa)

modelvars <- c("campaign_css", "affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black", "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs", "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south", "YEAR", "ACERECODE", "ace_year")

data.lis.polsub1.pa.temp <- polsub1.df[complete.cases(polsub1.df[,modelvars]),]
nrow(data.lis.polsub1.pa.temp)

campaign.lis.polsub1.pa.p <- summary(campaign.lis.polsub1.pa)$coefficients["factor(affcat)5",4] 

data.lis.polsub1.pa.temp$affcat <- 1
campaign.lis.polsub1.pa.lis.1 <- mean(predict(campaign.lis.polsub1.pa, data.lis.polsub1.pa.temp, re.form=NULL, type = "response")) 
data.lis.polsub1.pa.temp$affcat <- 5
campaign.lis.polsub1.pa.lis.5 <- mean(predict(campaign.lis.polsub1.pa, data.lis.polsub1.pa.temp, re.form=NULL, type = "response")) 
campaign.lis.polsub1.pa.eff <- campaign.lis.polsub1.pa.lis.5 - campaign.lis.polsub1.pa.lis.1
campaign.lis.polsub1.pa.eff

elected.lis.polsub1.pa <- glmer(elected01_gov ~ factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                                  hihispanicper + hiothraceper + hijewishper+ hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                                  socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                                  factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = polsub1.df) 
summary(elected.lis.polsub1.pa)

modelvars <- c("elected01_gov", "affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black", "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs", "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south", "YEAR", "ACERECODE", "ace_year")

data.lis.polsub1.pa.temp <- polsub1.df[complete.cases(polsub1.df[,modelvars]),]
nrow(data.lis.polsub1.pa.temp)

elected.lis.polsub1.pa.p <- summary(elected.lis.polsub1.pa)$coefficients["factor(affcat)5",4] 

data.lis.polsub1.pa.temp$affcat <- 1
elected.lis.polsub1.pa.lis.1 <- mean(predict(elected.lis.polsub1.pa, data.lis.polsub1.pa.temp, re.form=NULL, type = "response")) 
data.lis.polsub1.pa.temp$affcat <- 5
elected.lis.polsub1.pa.lis.5 <- mean(predict(elected.lis.polsub1.pa, data.lis.polsub1.pa.temp, re.form=NULL, type = "response")) 
elected.lis.polsub1.pa.eff <- elected.lis.polsub1.pa.lis.5 - elected.lis.polsub1.pa.lis.1
elected.lis.polsub1.pa.eff

orglead.lis.polsub1.pa <- glmer(orglead01  ~ factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                                  hihispanicper + hiothraceper + hijewishper+ hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                                  socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                                  factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = polsub1.df)  
summary(orglead.lis.polsub1.pa)

modelvars <- c("orglead01", "affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black", "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs", "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south", "YEAR", "ACERECODE", "ace_year")

data.lis.polsub1.pa.temp <- polsub1.df[complete.cases(polsub1.df[,modelvars]),]
nrow(data.lis.polsub1.pa.temp)#367

orglead.lis.polsub1.pa.p <- summary(orglead.lis.polsub1.pa)$coefficients["factor(affcat)5",4] 

data.lis.polsub1.pa.temp$affcat <- 1
orglead.lis.polsub1.pa.lis.1 <- mean(predict(orglead.lis.polsub1.pa, data.lis.polsub1.pa.temp, re.form=NULL, type = "response")) 
data.lis.polsub1.pa.temp$affcat <- 5
orglead.lis.polsub1.pa.lis.5 <- mean(predict(orglead.lis.polsub1.pa, data.lis.polsub1.pa.temp, re.form=NULL, type = "response")) 
orglead.lis.polsub1.pa.eff <- orglead.lis.polsub1.pa.lis.5 - orglead.lis.polsub1.pa.lis.1
orglead.lis.polsub1.pa.eff

protest.lis.polsub1.pa <- glmer(protestindex_css  ~  factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                                  hihispanicper + hiothraceper + hijewishper+ hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                                  socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                                  factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = polsub1.df) 
summary(protest.lis.polsub1.pa)

modelvars <- c("protestindex_css", "affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black", "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs", "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south", "YEAR", "ACERECODE", "ace_year")

data.lis.polsub1.pa.temp <- polsub1.df[complete.cases(polsub1.df[,modelvars]),]
nrow(data.lis.polsub1.pa.temp)

protest.lis.polsub1.pa.p <- summary(protest.lis.polsub1.pa)$coefficients["factor(affcat)5",4] 

data.lis.polsub1.pa.temp$affcat <- 1
protest.lis.polsub1.pa.lis.1 <- mean(predict(protest.lis.polsub1.pa, data.lis.polsub1.pa.temp, re.form=NULL, type = "response")) 
data.lis.polsub1.pa.temp$affcat <- 5
protest.lis.polsub1.pa.lis.5 <- mean(predict(protest.lis.polsub1.pa, data.lis.polsub1.pa.temp, re.form=NULL, type = "response")) 
protest.lis.polsub1.pa.eff <- protest.lis.polsub1.pa.lis.5 - protest.lis.polsub1.pa.lis.1
protest.lis.polsub1.pa.eff

######################
# Somewhat Important #
######################

polsub2.df <- data.lis[data.lis$GOAL18_TFS == 2 & !is.na(data.lis$GOAL18_TFS),]

# Models

passive.lis.polsub2.pa <- lmer(passive_index_css_avg ~ factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                                 evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                                 hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                                 age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                                 largesb + public + college + neast + south + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), data = polsub2.df) 
summary(passive.lis.polsub2.pa)

passive.re.lis.full.coefs.polsub2.pa <- data.frame(coef(summary(passive.lis.polsub2.pa)))
passive.re.lis.full.coefs.polsub2.pa$p.z <- 2 * (1 - pnorm(abs(passive.re.lis.full.coefs.polsub2.pa$t.value)))
passive.re.lis.full.coefs.polsub2.pa$p.z

modelvars <- c("passive_index_css_avg", "affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black", "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs", "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south", "YEAR", "ACERECODE", "ace_year")

data.lis.polsub2.pa.temp <- polsub2.df[complete.cases(polsub2.df[,modelvars]),]
nrow(data.lis.polsub2.pa.temp)

passive.lis.polsub2.pa.p <- summary(passive.lis.polsub2.pa)$coefficients["factor(affcat)5",5] 

data.lis.polsub2.pa.temp$affcat <- 1
passive.lis.polsub2.pa.lis.1 <- mean(predict(passive.lis.polsub2.pa, data.lis.polsub2.pa.temp, re.form=NULL)) 
data.lis.polsub2.pa.temp$affcat <- 5
passive.lis.polsub2.pa.lis.5 <- mean(predict(passive.lis.polsub2.pa, data.lis.polsub2.pa.temp, re.form=NULL)) 
passive.lis.polsub2.pa.eff <- passive.lis.polsub2.pa.lis.5 - passive.lis.polsub2.pa.lis.1
passive.lis.polsub2.pa.eff

voteprez2.lis.polsub2.pa <- glmer(voteprez2 ~ factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                                    hihispanicper + hiothraceper + hijewishper+ hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                                    socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                                    factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = polsub2.df) 
summary(voteprez2.lis.polsub2.pa)

modelvars <- c("voteprez2", "affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black", "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs", "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south", "YEAR", "ACERECODE", "ace_year")

data.lis.polsub2.pa.temp <- polsub2.df[complete.cases(polsub2.df[,modelvars]),]
nrow(data.lis.polsub2.pa.temp)

voteprez2.lis.polsub2.pa.p <- summary(voteprez2.lis.polsub2.pa)$coefficients["factor(affcat)5",4] 

data.lis.polsub2.pa.temp$affcat <- 1
voteprez2.lis.polsub2.pa.lis.1 <- mean(predict(voteprez2.lis.polsub2.pa, data.lis.polsub2.pa.temp, re.form=NULL, type = "response")) 
data.lis.polsub2.pa.temp$affcat <- 5
voteprez2.lis.polsub2.pa.lis.5 <- mean(predict(voteprez2.lis.polsub2.pa, data.lis.polsub2.pa.temp, re.form=NULL, type = "response")) 
voteprez2.lis.polsub2.pa.eff <- voteprez2.lis.polsub2.pa.lis.5 - voteprez2.lis.polsub2.pa.lis.1
voteprez2.lis.polsub2.pa.eff

campaign.lis.polsub2.pa <- glmer(campaign_css ~ factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                                   hihispanicper + hiothraceper + hijewishper+ hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                                   socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                                   factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = polsub2.df) 
summary(campaign.lis.polsub2.pa)

modelvars <- c("campaign_css", "affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black", "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs", "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south", "YEAR", "ACERECODE", "ace_year")

data.lis.polsub2.pa.temp <- polsub2.df[complete.cases(polsub2.df[,modelvars]),]
nrow(data.lis.polsub2.pa.temp)

campaign.lis.polsub2.pa.p <- summary(campaign.lis.polsub2.pa)$coefficients["factor(affcat)5",4] 

data.lis.polsub2.pa.temp$affcat <- 1
campaign.lis.polsub2.pa.lis.1 <- mean(predict(campaign.lis.polsub2.pa, data.lis.polsub2.pa.temp, re.form=NULL, type = "response")) 
data.lis.polsub2.pa.temp$affcat <- 5
campaign.lis.polsub2.pa.lis.5 <- mean(predict(campaign.lis.polsub2.pa, data.lis.polsub2.pa.temp, re.form=NULL, type = "response")) 
campaign.lis.polsub2.pa.eff <- campaign.lis.polsub2.pa.lis.5 - campaign.lis.polsub2.pa.lis.1
campaign.lis.polsub2.pa.eff

elected.lis.polsub2.pa <- glmer(elected01_gov ~ factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                                  hihispanicper + hiothraceper + hijewishper+ hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                                  socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                                  factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = polsub2.df) 
summary(elected.lis.polsub2.pa)

modelvars <- c("elected01_gov", "affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black", "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs", "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south", "YEAR", "ACERECODE", "ace_year")

data.lis.polsub2.pa.temp <- polsub2.df[complete.cases(polsub2.df[,modelvars]),]
nrow(data.lis.polsub2.pa.temp)

elected.lis.polsub2.pa.p <- summary(elected.lis.polsub2.pa)$coefficients["factor(affcat)5",4] 

data.lis.polsub2.pa.temp$affcat <- 1
elected.lis.polsub2.pa.lis.1 <- mean(predict(elected.lis.polsub2.pa, data.lis.polsub2.pa.temp, re.form=NULL, type = "response")) 
data.lis.polsub2.pa.temp$affcat <- 5
elected.lis.polsub2.pa.lis.5 <- mean(predict(elected.lis.polsub2.pa, data.lis.polsub2.pa.temp, re.form=NULL, type = "response")) 
elected.lis.polsub2.pa.eff <- elected.lis.polsub2.pa.lis.5 - elected.lis.polsub2.pa.lis.1
elected.lis.polsub2.pa.eff

orglead.lis.polsub2.pa <- glmer(orglead01  ~ factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                                  hihispanicper + hiothraceper + hijewishper+ hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                                  socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                                  factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = polsub2.df)  
summary(orglead.lis.polsub2.pa)

modelvars <- c("orglead01", "affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black", "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs", "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south", "YEAR", "ACERECODE", "ace_year")

data.lis.polsub2.pa.temp <- polsub2.df[complete.cases(polsub2.df[,modelvars]),]
nrow(data.lis.polsub2.pa.temp)#367

orglead.lis.polsub2.pa.p <- summary(orglead.lis.polsub2.pa)$coefficients["factor(affcat)5",4] 

data.lis.polsub2.pa.temp$affcat <- 1
orglead.lis.polsub2.pa.lis.1 <- mean(predict(orglead.lis.polsub2.pa, data.lis.polsub2.pa.temp, re.form=NULL, type = "response")) 
data.lis.polsub2.pa.temp$affcat <- 5
orglead.lis.polsub2.pa.lis.5 <- mean(predict(orglead.lis.polsub2.pa, data.lis.polsub2.pa.temp, re.form=NULL, type = "response")) 
orglead.lis.polsub2.pa.eff <- orglead.lis.polsub2.pa.lis.5 - orglead.lis.polsub2.pa.lis.1
orglead.lis.polsub2.pa.eff

protest.lis.polsub2.pa <- glmer(protestindex_css  ~  factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                                  hihispanicper + hiothraceper + hijewishper+ hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                                  socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                                  factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = polsub2.df) 
summary(protest.lis.polsub2.pa)

modelvars <- c("protestindex_css", "affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black", "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs", "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south", "YEAR", "ACERECODE", "ace_year")

data.lis.polsub2.pa.temp <- polsub2.df[complete.cases(polsub2.df[,modelvars]),]
nrow(data.lis.polsub2.pa.temp)

protest.lis.polsub2.pa.p <- summary(protest.lis.polsub2.pa)$coefficients["factor(affcat)5",4] 

data.lis.polsub2.pa.temp$affcat <- 1
protest.lis.polsub2.pa.lis.1 <- mean(predict(protest.lis.polsub2.pa, data.lis.polsub2.pa.temp, re.form=NULL, type = "response")) 
data.lis.polsub2.pa.temp$affcat <- 5
protest.lis.polsub2.pa.lis.5 <- mean(predict(protest.lis.polsub2.pa, data.lis.polsub2.pa.temp, re.form=NULL, type = "response")) 
protest.lis.polsub2.pa.eff <- protest.lis.polsub2.pa.lis.5 - protest.lis.polsub2.pa.lis.1
protest.lis.polsub2.pa.eff

##############################
# Very Important & Essential #
##############################

polsub3.df <- data.lis[(data.lis$GOAL18_TFS == 3 | data.lis$GOAL18_TFS == 4) 
                         & !is.na(data.lis$GOAL18_TFS),]

# Models

passive.lis.polsub3.pa <- lmer(passive_index_css_avg ~ factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                                 evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                                 hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                                 age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                                 largesb + public + college + neast + south + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), data = polsub3.df) 
summary(passive.lis.polsub3.pa)

passive.re.lis.full.coefs.polsub3.pa <- data.frame(coef(summary(passive.lis.polsub3.pa)))
passive.re.lis.full.coefs.polsub3.pa$p.z <- 2 * (1 - pnorm(abs(passive.re.lis.full.coefs.polsub3.pa$t.value)))
passive.re.lis.full.coefs.polsub3.pa$p.z

modelvars <- c("passive_index_css_avg", "affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black", "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs", "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south", "YEAR", "ACERECODE", "ace_year")

data.lis.polsub3.pa.temp <- polsub3.df[complete.cases(polsub3.df[,modelvars]),]
nrow(data.lis.polsub3.pa.temp)

passive.lis.polsub3.pa.p <- summary(passive.lis.polsub3.pa)$coefficients["factor(affcat)5",5] 

data.lis.polsub3.pa.temp$affcat <- 1
passive.lis.polsub3.pa.lis.1 <- mean(predict(passive.lis.polsub3.pa, data.lis.polsub3.pa.temp, re.form=NULL)) 
data.lis.polsub3.pa.temp$affcat <- 5
passive.lis.polsub3.pa.lis.5 <- mean(predict(passive.lis.polsub3.pa, data.lis.polsub3.pa.temp, re.form=NULL)) 
passive.lis.polsub3.pa.eff <- passive.lis.polsub3.pa.lis.5 - passive.lis.polsub3.pa.lis.1
passive.lis.polsub3.pa.eff

voteprez2.lis.polsub3.pa <- glmer(voteprez2 ~ factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                                    hihispanicper + hiothraceper + hijewishper+ hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                                    socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                                    factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = polsub3.df) 
summary(voteprez2.lis.polsub3.pa)

modelvars <- c("voteprez2", "affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black", "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs", "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south", "YEAR", "ACERECODE", "ace_year")

data.lis.polsub3.pa.temp <- polsub3.df[complete.cases(polsub3.df[,modelvars]),]
nrow(data.lis.polsub3.pa.temp)

voteprez2.lis.polsub3.pa.p <- summary(voteprez2.lis.polsub3.pa)$coefficients["factor(affcat)5",4] 

data.lis.polsub3.pa.temp$affcat <- 1
voteprez2.lis.polsub3.pa.lis.1 <- mean(predict(voteprez2.lis.polsub3.pa, data.lis.polsub3.pa.temp, re.form=NULL, type = "response")) 
data.lis.polsub3.pa.temp$affcat <- 5
voteprez2.lis.polsub3.pa.lis.5 <- mean(predict(voteprez2.lis.polsub3.pa, data.lis.polsub3.pa.temp, re.form=NULL, type = "response")) 
voteprez2.lis.polsub3.pa.eff <- voteprez2.lis.polsub3.pa.lis.5 - voteprez2.lis.polsub3.pa.lis.1
voteprez2.lis.polsub3.pa.eff

campaign.lis.polsub3.pa <- glmer(campaign_css ~ factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                                   hihispanicper + hiothraceper + hijewishper+ hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                                   socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                                   factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = polsub3.df) 
summary(campaign.lis.polsub3.pa)

modelvars <- c("campaign_css", "affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black", "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs", "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south", "YEAR", "ACERECODE", "ace_year")

data.lis.polsub3.pa.temp <- polsub3.df[complete.cases(polsub3.df[,modelvars]),]
nrow(data.lis.polsub3.pa.temp)

campaign.lis.polsub3.pa.p <- summary(campaign.lis.polsub3.pa)$coefficients["factor(affcat)5",4] 

data.lis.polsub3.pa.temp$affcat <- 1
campaign.lis.polsub3.pa.lis.1 <- mean(predict(campaign.lis.polsub3.pa, data.lis.polsub3.pa.temp, re.form=NULL, type = "response")) 
data.lis.polsub3.pa.temp$affcat <- 5
campaign.lis.polsub3.pa.lis.5 <- mean(predict(campaign.lis.polsub3.pa, data.lis.polsub3.pa.temp, re.form=NULL, type = "response")) 
campaign.lis.polsub3.pa.eff <- campaign.lis.polsub3.pa.lis.5 - campaign.lis.polsub3.pa.lis.1
campaign.lis.polsub3.pa.eff

elected.lis.polsub3.pa <- glmer(elected01_gov ~ factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                                  hihispanicper + hiothraceper + hijewishper+ hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                                  socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                                  factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = polsub3.df) 
summary(elected.lis.polsub3.pa)

modelvars <- c("elected01_gov", "affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black", "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs", "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south", "YEAR", "ACERECODE", "ace_year")

data.lis.polsub3.pa.temp <- polsub3.df[complete.cases(polsub3.df[,modelvars]),]
nrow(data.lis.polsub3.pa.temp)

elected.lis.polsub3.pa.p <- summary(elected.lis.polsub3.pa)$coefficients["factor(affcat)5",4] 

data.lis.polsub3.pa.temp$affcat <- 1
elected.lis.polsub3.pa.lis.1 <- mean(predict(elected.lis.polsub3.pa, data.lis.polsub3.pa.temp, re.form=NULL, type = "response")) 
data.lis.polsub3.pa.temp$affcat <- 5
elected.lis.polsub3.pa.lis.5 <- mean(predict(elected.lis.polsub3.pa, data.lis.polsub3.pa.temp, re.form=NULL, type = "response")) 
elected.lis.polsub3.pa.eff <- elected.lis.polsub3.pa.lis.5 - elected.lis.polsub3.pa.lis.1
elected.lis.polsub3.pa.eff

orglead.lis.polsub3.pa <- glmer(orglead01  ~ factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                                  hihispanicper + hiothraceper + hijewishper+ hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                                  socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                                  factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = polsub3.df)  
summary(orglead.lis.polsub3.pa)

modelvars <- c("orglead01", "affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black", "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs", "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south", "YEAR", "ACERECODE", "ace_year")

data.lis.polsub3.pa.temp <- polsub3.df[complete.cases(polsub3.df[,modelvars]),]
nrow(data.lis.polsub3.pa.temp)#367

orglead.lis.polsub3.pa.p <- summary(orglead.lis.polsub3.pa)$coefficients["factor(affcat)5",4] 

data.lis.polsub3.pa.temp$affcat <- 1
orglead.lis.polsub3.pa.lis.1 <- mean(predict(orglead.lis.polsub3.pa, data.lis.polsub3.pa.temp, re.form=NULL, type = "response")) 
data.lis.polsub3.pa.temp$affcat <- 5
orglead.lis.polsub3.pa.lis.5 <- mean(predict(orglead.lis.polsub3.pa, data.lis.polsub3.pa.temp, re.form=NULL, type = "response")) 
orglead.lis.polsub3.pa.eff <- orglead.lis.polsub3.pa.lis.5 - orglead.lis.polsub3.pa.lis.1
orglead.lis.polsub3.pa.eff

protest.lis.polsub3.pa <- glmer(protestindex_css  ~  factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                                  hihispanicper + hiothraceper + hijewishper+ hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                                  socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                                  factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = polsub3.df) 
summary(protest.lis.polsub3.pa)

modelvars <- c("protestindex_css", "affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black", "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs", "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south", "YEAR", "ACERECODE", "ace_year")

data.lis.polsub3.pa.temp <- polsub3.df[complete.cases(polsub3.df[,modelvars]),]
nrow(data.lis.polsub3.pa.temp)

protest.lis.polsub3.pa.p <- summary(protest.lis.polsub3.pa)$coefficients["factor(affcat)5",4] 

data.lis.polsub3.pa.temp$affcat <- 1
protest.lis.polsub3.pa.lis.1 <- mean(predict(protest.lis.polsub3.pa, data.lis.polsub3.pa.temp, re.form=NULL, type = "response")) 
data.lis.polsub3.pa.temp$affcat <- 5
protest.lis.polsub3.pa.lis.5 <- mean(predict(protest.lis.polsub3.pa, data.lis.polsub3.pa.temp, re.form=NULL, type = "response")) 
protest.lis.polsub3.pa.eff <- protest.lis.polsub3.pa.lis.5 - protest.lis.polsub3.pa.lis.1
protest.lis.polsub3.pa.eff

# Predicted Effects Figure

data = data.frame (variable = c("Lead Student Organization", 
                                "Lead Student Organization", 
                                "Lead Student Organization", 
                                "Lead Student Organization", 
                                "Protest Involvement", 
                                "Protest Involvement", 
                                "Protest Involvement", 
                                "Protest Involvement", 
                                "Passive Engagement Index",
                                "Passive Engagement Index",
                                "Passive Engagement Index",
                                "Passive Engagement Index",
                                "Vote in National Election",  
                                "Vote in National Election",  
                                "Vote in National Election",  
                                "Vote in National Election",  
                                "Participate in Campaign", 
                                "Participate in Campaign", 
                                "Participate in Campaign", 
                                "Participate in Campaign", 
                                "Participate in Student Government",
                                "Participate in Student Government",
                                "Participate in Student Government",
                                "Participate in Student Government"),
                   level= c("Low", 
                            "Medium",
                            "High",
                            "All LIS"),
                   effect = c(0, 
                              0, 
                              0, 
                              orglead.lis.eff, 
                              protest.lis.polsub1.pa.eff, 
                              protest.lis.polsub2.pa.eff, 
                              protest.lis.polsub3.pa.eff, 
                              protest.lis.eff, 
                              passive.lis.polsub1.pa.eff, 
                              passive.lis.polsub2.pa.eff, 
                              passive.lis.polsub3.pa.eff, 
                              passive.lis.eff, 
                              voteprez2.lis.polsub1.pa.eff, 
                              voteprez2.lis.polsub2.pa.eff, 
                              voteprez2.lis.polsub3.pa.eff, 
                              voteprez2.lis.eff, 
                              campaign.lis.polsub1.pa.eff, 
                              campaign.lis.polsub2.pa.eff, 
                              campaign.lis.polsub3.pa.eff, 
                              campaign.lis.eff, 
                              elected.lis.polsub1.pa.eff, 
                              elected.lis.polsub2.pa.eff, 
                              elected.lis.polsub3.pa.eff, 
                              elected.lis.eff),
                   sig = c(10, 
                           10, 
                           10, 
                           orglead.lis.p, 
                           protest.lis.polsub1.pa.p, 
                           protest.lis.polsub2.pa.p, 
                           protest.lis.polsub3.pa.p, 
                           protest.lis.p, 
                           passive.lis.polsub1.pa.p, 
                           passive.lis.polsub2.pa.p, 
                           passive.lis.polsub3.pa.p, 
                           passive.lis.p, 
                           voteprez2.lis.polsub1.pa.p, 
                           voteprez2.lis.polsub2.pa.p, 
                           voteprez2.lis.polsub3.pa.p, 
                           voteprez2.lis.p, 
                           campaign.lis.polsub1.pa.p, 
                           campaign.lis.polsub2.pa.p, 
                           campaign.lis.polsub3.pa.p, 
                           campaign.lis.p, 
                           elected.lis.polsub1.pa.p, 
                           elected.lis.polsub2.pa.p, 
                           elected.lis.polsub3.pa.p, 
                           elected.lis.p)) 

data$sig <- ifelse(data$sig == 10, "INSUFF.\nDATA\n\n",
                   ifelse(data$sig >= .05 & data$sig != 10, "n.s",
                          ifelse(data$sig < .05 &
                                   data$sig >= .01, "*",
                                 ifelse(data$sig < .01 &
                                          data$sig >= .001, "**",
                                        ifelse(data$sig < .001, "***", NA)))))

data$level <- factor(data$level , levels = c("All LIS", 
                                             "Low",
                                             "Medium",
                                             "High"))

p1<- ggplot(data[1:4,], aes(x=level, y=effect*100, fill=level)) +
  facet_grid(.~variable) +
  geom_bar(stat="identity") +
  ylab("Percentage Point Effect") +
  guides(fill=FALSE) +
  theme_bw() +
  theme(text = element_text(size=12, face="bold"), axis.title.x=element_blank()) +
  geom_hline(yintercept=0, linetype = "dashed") +
  scale_y_continuous(limits=c(-05, 47)) +
  theme(text = element_text(size=20)) +
  geom_text(aes(x=level, y=ifelse(sig=="n.s", 1.8, .8), 
                label=sig), 
            position = position_dodge(width=1), size = 7)

p2<-ggplot(data[5:8,], aes(x=level, y=effect*100, fill=level)) +
  facet_grid(.~variable) +
  geom_bar(stat="identity") +
  guides(fill=FALSE) +
  theme_bw() +
  theme(text = element_text(size=12, face="bold"), axis.title.y=element_blank(), axis.title.x=element_blank()) +
  geom_hline(yintercept=0, linetype = "dashed") +
  scale_y_continuous(limits=c(-1, 10)) +
  geom_text(aes(x=level, y=ifelse(sig=="n.s", .4, ifelse(sig=="INSUFF.\nDATA", 1.0, .3)), 
                label=sig), 
            position = position_dodge(width=1), size = 7) + theme(text = element_text(size=20)) 

p3<-ggplot(data[9:12,], aes(x=level, y=effect*100, fill=level)) +
  facet_grid(.~variable) +
  geom_bar(stat="identity") +
  guides(fill=FALSE) +
  theme_bw() +
  theme(text = element_text(size=12, face="bold"), axis.title.y=element_blank(), axis.title.x=element_blank()) +
  geom_hline(yintercept=0, linetype = "dashed") +
  scale_y_continuous(limits=c(-1, 10)) +
  geom_text(aes(x=level, y=ifelse(sig=="n.s", .4, .3), 
                label=sig), 
            position = position_dodge(width=1), size = 7) + theme(text = element_text(size=20)) 

p4<-ggplot(data[13:16,], aes(x=level, y=effect*100, fill=level)) +
  facet_grid(.~variable) +
  geom_bar(stat="identity") +
  ylab("Percentage Point Effect") +
  guides(fill=FALSE) +
  theme_bw() +
  theme(text = element_text(size=12, face="bold"), axis.title.x=element_blank()) +
  geom_hline(yintercept=0, linetype = "dashed") +
  scale_y_continuous(limits=c(-2, 15)) +
  geom_text(aes(x=level, y=ifelse(sig=="n.s", .8, .4), 
                label=sig), 
            position = position_dodge(width=1), size = 7) + theme(text = element_text(size=20)) 

p5<-ggplot(data[17:20,], aes(x=level, y=effect*100, fill=level)) +
  facet_grid(.~variable) +
  geom_bar(stat="identity") +
  guides(fill=FALSE) +
  theme_bw() +
  theme(text = element_text(size=12, face="bold"), axis.title.y=element_blank(), axis.title.x=element_blank()) +
  geom_hline(yintercept=0, linetype = "dashed") +
  scale_y_continuous(limits=c(-2, 15)) +
  geom_text(aes(x=level, y=ifelse(sig=="n.s", .8, ifelse(sig=="INSUFF.\nDATA", 1.6, .3)), 
                label=sig), 
            position = position_dodge(width=1), size = 7) + theme(text = element_text(size=20)) 

p6<-ggplot(data[21:24,], aes(x=level, y=effect*100, fill=level)) +
  facet_grid(.~variable) +
  geom_bar(stat="identity") +
  guides(fill=FALSE) +
  theme_bw() +
  theme(text = element_text(size=12, face="bold"), axis.title.y=element_blank(), axis.title.x=element_blank()) +
  geom_hline(yintercept=0, linetype = "dashed") +
  scale_y_continuous(limits=c(-12.6, 15)) +
  geom_text(aes(x=level, y=ifelse(sig=="n.s", .8,  ifelse(sig=="INSUFF.\nDATA", 2.3, .3)), 
                label=sig), 
            position = position_dodge(width=1), size = 7) + theme(text = element_text(size=20)) 

grid.arrange(p1, p2, p3, p4, p5, p6, nrow=2)

#####################
# Appendix Figure 6 #
#####################

small <- read.dta("attrition_small_limited.dta")

small$weights_level2 <- ifelse(small$csstaken == 1, 1/small$predictlevel2, 1/(1-small$predictlevel2))
small$weights_level2_lis <- ifelse(small$csstaken == 1, 1/small$predictlevel2_lis, 1/(1-small$predictlevel2_lis))
small$weights_level2_mis <- ifelse(small$csstaken == 1, 1/small$predictlevel2_mis, 1/(1-small$predictlevel2_mis))
small$weights_level2_his <- ifelse(small$csstaken == 1, 1/small$predictlevel2_his, 1/(1-small$predictlevel2_his))

#########################
# Level 2, Small #
#########################



describe(small$weights_level2)

passive.lis <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + factor(affcat) + hitestscore_y + testscore_na +  female_y +  asian_y +  hispanic_y + black_y +  othrace_y +
                      jewish_y +  catholic_y + evangelical_y + otherornorelig_y + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                      businesstfs + makemoneyvimp_y +  hitestscoreper_y + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                      hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                      makemoneyvimpper_y +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS_y) + (1 | ACERECODE) + (1 | ace_year),
                    data = small[small$csstaken ==1 & small$parinc_y == "Low-Income",], weights=(weights_level2))  


passive.mis <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + factor(affcat) + hitestscore_y + testscore_na +  female_y +  asian_y +  hispanic_y + black_y +  othrace_y +
                      jewish_y +  catholic_y + evangelical_y + otherornorelig_y + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                      businesstfs + makemoneyvimp_y +  hitestscoreper_y + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                      hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                      makemoneyvimpper_y +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS_y) + (1 | ACERECODE) + (1 | ace_year),
                    data = small[small$csstaken ==1 & small$parinc_y == "Middle-Income",], weights=(weights_level2))  


passive.his <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + factor(affcat) + hitestscore_y + testscore_na +  female_y +  asian_y +  hispanic_y + black_y +  othrace_y +
                      jewish_y +  catholic_y + evangelical_y + otherornorelig_y + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                      businesstfs + makemoneyvimp_y +  hitestscoreper_y + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                      hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                      makemoneyvimpper_y +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS_y) + (1 | ACERECODE) + (1 | ace_year),
                    data = small[small$csstaken ==1 & small$parinc_y == "High-Income",], weights=(weights_level2))  

summary(passive.lis)
summary(passive.mis)
summary(passive.his)


modelvars <- c("passive_index_css_avg", "passive_index_tfs_avg", "affcat", "hitestscore_y", "female_y", "asian_y", "hispanic_y", "black_y", "othrace_y",
               "jewish_y", "catholic_y", "evangelical_y", "otherornorelig_y", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs", "makemoneyvimp_y",  "hitestscoreper_y",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper_y", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south", "YEAR_TFS_y", "ACERECODE", "ace_year", "weights_level2", "csstaken", "parinc_y")

small2 <- small[complete.cases(small[,modelvars]),]

data.lis.temp  <- small2[small2$csstaken ==1 & small2$parinc_y == "Low-Income",]
data.mis.temp  <- small2[small2$csstaken ==1 & small2$parinc_y == "Middle-Income",]
data.his.temp  <- small2[small2$csstaken ==1 & small2$parinc_y == "High-Income",]


passive.lis.p <- summary(passive.lis)$coefficients["factor(affcat)5", 5] 


data.lis.temp$affcat <- 1
passive.lis.pred.1 <- mean(predict(passive.lis, data.lis.temp, re.form=NULL)) 
data.lis.temp$affcat <- 5
passive.lis.pred.5 <- mean(predict(passive.lis, data.lis.temp, re.form=NULL)) 
passive.lis.eff <- passive.lis.pred.5 - passive.lis.pred.1

passive.mis.p <- summary(passive.mis)$coefficients["factor(affcat)5",5] 

data.mis.temp$affcat <- 1
passive.mis.pred.1 <- mean(predict(passive.mis, data.mis.temp, re.form=NULL)) 
data.mis.temp$affcat <- 5
passive.mis.pred.5 <- mean(predict(passive.mis, data.mis.temp, re.form=NULL)) 
passive.mis.eff <- passive.mis.pred.5 - passive.mis.pred.1

passive.his.p <- summary(passive.his)$coefficients["factor(affcat)5",5] 

data.his.temp$affcat <- 1
passive.his.pred.1 <- mean(predict(passive.his, data.his.temp, re.form=NULL)) 
data.his.temp$affcat <- 5
passive.his.pred.5 <- mean(predict(passive.his, data.his.temp, re.form=NULL)) 
passive.his.eff <- passive.his.pred.5 - passive.his.pred.1



##########
# Voting #
##########

table(small$YEAR_TFS)
table(small$YEAR)

# Act in college: Voted in a state/national election (1995 - 1998)

table(small$COLACT36_9406)
table(small$COLACT36_9406, small$YEAR) #95-98 in YEAR (not YEAR_TFS - there 90-94)

small$vote9598 <- ifelse(small$COLACT36_9406 == "Marked", 1, 0)

# Act in past year: Voted in a state/national election

table(small$GENACT36)
table(small$GENACT36, small$YEAR) #99-01 (in TFS_YEAR it is 95-98)

small$vote9901 <- ifelse(small$GENACT36 == "Not at all", 0, 1)

table(small$vote9901, small$YEAR)


# Vote in a general election

small$voteprez2 <- ifelse(small$YEAR %in% 1990:1994, small$vote9598,
                                ifelse(small$YEAR %in% 1995:1998, small$vote9901, NA))


table(small$voteprez2)
table(small$polaffairs_tfs)


voteprez.lis <- glmer(voteprez2 ~ polaffairs_tfs +  factor(affcat) + hitestscore_y + testscore_na +  female_y +  asian_y +  hispanic_y + black_y +  othrace_y +
                        jewish_y +  catholic_y + evangelical_y + otherornorelig_y + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                        businesstfs + makemoneyvimp_y +  hitestscoreper_y + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                        hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                        makemoneyvimpper_y +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS_y) + (1 | ACERECODE) + (1 | ace_year),
                      family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                      data = small[small$csstaken ==1 & small$parinc_y == "Low-Income",], weights=(weights_level2))  




voteprez.mis <- glmer(voteprez2 ~ polaffairs_tfs +  factor(affcat) + hitestscore_y + testscore_na +  female_y +  asian_y +  hispanic_y + black_y +  othrace_y +
                        jewish_y +  catholic_y + evangelical_y + otherornorelig_y + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                        businesstfs + makemoneyvimp_y +  hitestscoreper_y + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                        hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                        makemoneyvimpper_y +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS_y) + (1 | ACERECODE) + (1 | ace_year),
                      family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                      data = small[small$csstaken ==1 & small$parinc_y == "Middle-Income",], weights=(weights_level2))  


voteprez.his <- glmer(voteprez2 ~ polaffairs_tfs +  factor(affcat) + hitestscore_y + testscore_na +  female_y +  asian_y +  hispanic_y + black_y +  othrace_y +
                        jewish_y +  catholic_y + evangelical_y + otherornorelig_y + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                        businesstfs + makemoneyvimp_y +  hitestscoreper_y + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                        hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                        makemoneyvimpper_y +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS_y) + (1 | ACERECODE) + (1 | ace_year),
                      family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                      data = small[small$csstaken ==1 & small$parinc_y == "High-Income",], weights=(weights_level2))  


modelvars <- c("voteprez2", "polaffairs_tfs", "affcat", "hitestscore_y", "female_y", "asian_y", "hispanic_y", "black_y", "othrace_y",
               "jewish_y", "catholic_y", "evangelical_y", "otherornorelig_y", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs", "makemoneyvimp_y",  "hitestscoreper_y",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper_y", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south", "YEAR_TFS_y", "ACERECODE", "ace_year", "csstaken", "weights_level2", "parinc_y")


small2 <- small[complete.cases(small[,modelvars]),]

data.lis.temp  <- small2[small2$csstaken ==1 & small2$parinc_y == "Low-Income",]
data.mis.temp  <- small2[small2$csstaken ==1 & small2$parinc_y == "Middle-Income",]
data.his.temp  <- small2[small2$csstaken ==1 & small2$parinc_y == "High-Income",]


voteprez.lis.p <- summary(voteprez.lis)$coefficients["factor(affcat)5",4] 

data.lis.temp$affcat <- 1
voteprez.lis.pred.1 <- mean(predict(voteprez.lis, data.lis.temp, re.form=NULL, type = "response")) 
data.lis.temp$affcat <- 5
voteprez.lis.pred.5 <- mean(predict(voteprez.lis, data.lis.temp, re.form=NULL, type = "response")) 
voteprez.lis.eff <- voteprez.lis.pred.5 - voteprez.lis.pred.1



voteprez.mis.p <- summary(voteprez.mis)$coefficients["factor(affcat)5",4] 

data.mis.temp$affcat <- 1
voteprez.mis.pred.1 <- mean(predict(voteprez.mis, data.mis.temp, re.form=NULL, type = "response")) 
data.mis.temp$affcat <- 5
voteprez.mis.pred.5 <- mean(predict(voteprez.mis, data.mis.temp, re.form=NULL, type = "response")) 
voteprez.mis.eff <- voteprez.mis.pred.5 - voteprez.mis.pred.1


voteprez.his.p <- summary(voteprez.his)$coefficients["factor(affcat)5",4] 

data.his.temp$affcat <- 1
voteprez.his.pred.1 <- mean(predict(voteprez.his, data.his.temp, re.form=NULL, type = "response")) 
data.his.temp$affcat <- 5
voteprez.his.pred.5 <- mean(predict(voteprez.his, data.his.temp, re.form=NULL, type = "response")) 
voteprez.his.eff <- voteprez.his.pred.5 - voteprez.his.pred.1



###############
# Campaigning #
###############

table(small$campaign_css)
table(small$campaign_tfs)


campaign.lis <- glmer(campaign_css ~ campaign_tfs + factor(affcat) + hitestscore_y + testscore_na +  female_y +  asian_y +  hispanic_y + black_y +  othrace_y +
                        jewish_y +  catholic_y + evangelical_y + otherornorelig_y + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                        businesstfs + makemoneyvimp_y +  hitestscoreper_y + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                        hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                        makemoneyvimpper_y +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS_y) + (1 | ACERECODE) + (1 | ace_year),
                      family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                      data = small[small$csstaken ==1 & small$parinc_y == "Low-Income",], weights=(weights_level2))  


# Middle-Income

campaign.mis <- glmer(campaign_css ~ campaign_tfs + factor(affcat) + hitestscore_y + testscore_na +  female_y +  asian_y +  hispanic_y + black_y +  othrace_y +
                        jewish_y +  catholic_y + evangelical_y + otherornorelig_y + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                        businesstfs + makemoneyvimp_y +  hitestscoreper_y + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                        hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                        makemoneyvimpper_y +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS_y) + (1 | ACERECODE) + (1 | ace_year),
                      family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                      data = small[small$csstaken ==1 & small$parinc_y == "Middle-Income",], weights=(weights_level2))  


# High-Income

campaign.his <- glmer(campaign_css ~ campaign_tfs + factor(affcat) + hitestscore_y + testscore_na +  female_y +  asian_y +  hispanic_y + black_y +  othrace_y +
                        jewish_y +  catholic_y + evangelical_y + otherornorelig_y + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                        businesstfs + makemoneyvimp_y +  hitestscoreper_y + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                        hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                        makemoneyvimpper_y +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS_y) + (1 | ACERECODE) + (1 | ace_year),
                      family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                      data = small[small$csstaken ==1 & small$parinc_y == "High-Income",], weights=(weights_level2))  



modelvars <- c("campaign_css", "campaign_tfs", "affcat", "hitestscore_y", "female_y", "asian_y", "hispanic_y", "black_y", "othrace_y",
               "jewish_y", "catholic_y", "evangelical_y", "otherornorelig_y", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs", "makemoneyvimp_y",  "hitestscoreper_y",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper_y", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south", "YEAR_TFS_y", "ACERECODE", "ace_year", "csstaken", "weights_level2", "parinc_y")


small2 <- small[complete.cases(small[,modelvars]),]

data.lis.temp  <- small2[small2$csstaken ==1 & small2$parinc_y == "Low-Income",]
data.mis.temp  <- small2[small2$csstaken ==1 & small2$parinc_y == "Middle-Income",]
data.his.temp  <- small2[small2$csstaken ==1 & small2$parinc_y == "High-Income",]



campaign.lis.p <- summary(campaign.lis)$coefficients["factor(affcat)5",4] 

data.lis.temp$affcat <- 1
campaign.lis.pred.1 <- mean(predict(campaign.lis, data.lis.temp, re.form=NULL, type = "response")) 
data.lis.temp$affcat <- 5
campaign.lis.pred.5 <- mean(predict(campaign.lis, data.lis.temp, re.form=NULL, type = "response")) 
campaign.lis.eff <- campaign.lis.pred.5 - campaign.lis.pred.1


campaign.mis.p <- summary(campaign.mis)$coefficients["factor(affcat)5",4] 

data.mis.temp$affcat <- 1
campaign.mis.pred.1 <- mean(predict(campaign.mis, data.mis.temp, re.form=NULL, type = "response")) 
data.mis.temp$affcat <- 5
campaign.mis.pred.5 <- mean(predict(campaign.mis, data.mis.temp, re.form=NULL, type = "response")) 
campaign.mis.eff <- campaign.mis.pred.5 - campaign.mis.pred.1


campaign.his.p <- summary(campaign.his)$coefficients["factor(affcat)5",4] 

data.his.temp$affcat <- 1
campaign.his.pred.1 <- mean(predict(campaign.his, data.his.temp, re.form=NULL, type = "response")) 
data.his.temp$affcat <- 5
campaign.his.pred.5 <- mean(predict(campaign.his, data.his.temp, re.form=NULL, type = "response")) 
campaign.his.eff <- campaign.his.pred.5 - campaign.his.pred.1



#############################
# Elected to Student Office #
#############################

table(small$elected01_gov)
table(small$commlead_tfs)

elected.lis <- glmer(elected01_gov ~ commlead_tfs + factor(affcat) + hitestscore_y + testscore_na +  female_y +  asian_y +  hispanic_y + black_y +  othrace_y +
                       jewish_y +  catholic_y + evangelical_y + otherornorelig_y + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                       businesstfs + makemoneyvimp_y +  hitestscoreper_y + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                       hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                       makemoneyvimpper_y +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS_y) + (1 | ACERECODE) + (1 | ace_year),
                     family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                     data = small[small$csstaken ==1 & small$parinc_y == "Low-Income",], weights=(weights_level2))  



# Middle-Income

elected.mis <- glmer(elected01_gov ~ commlead_tfs + factor(affcat) + hitestscore_y + testscore_na +  female_y +  asian_y +  hispanic_y + black_y +  othrace_y +
                       jewish_y +  catholic_y + evangelical_y + otherornorelig_y + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                       businesstfs + makemoneyvimp_y +  hitestscoreper_y + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                       hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                       makemoneyvimpper_y +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS_y) + (1 | ACERECODE) + (1 | ace_year),
                     family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                     data = small[small$csstaken ==1 & small$parinc_y == "Middle-Income",], weights=(weights_level2))  



# High-Income

elected.his <- glmer(elected01_gov ~ commlead_tfs + factor(affcat) + hitestscore_y + testscore_na +  female_y +  asian_y +  hispanic_y + black_y +  othrace_y +
                       jewish_y +  catholic_y + evangelical_y + otherornorelig_y + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                       businesstfs + makemoneyvimp_y +  hitestscoreper_y + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                       hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                       makemoneyvimpper_y +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS_y) + (1 | ACERECODE) + (1 | ace_year),
                     family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                     data = small[small$csstaken ==1 & small$parinc_y == "High-Income",], weights=(weights_level2))  



modelvars <- c("elected01_gov", "commlead_tfs", "affcat", "hitestscore_y", "female_y", "asian_y", "hispanic_y", "black_y", "othrace_y",
               "jewish_y", "catholic_y", "evangelical_y", "otherornorelig_y", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs", "makemoneyvimp_y",  "hitestscoreper_y",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper_y", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south", "YEAR_TFS_y", "ACERECODE", "ace_year", "csstaken", "weights_level2", "parinc_y")


small2 <- small[complete.cases(small[,modelvars]),]

data.lis.temp  <- small2[small2$csstaken ==1 & small2$parinc_y == "Low-Income",]
data.mis.temp  <- small2[small2$csstaken ==1 & small2$parinc_y == "Middle-Income",]
data.his.temp  <- small2[small2$csstaken ==1 & small2$parinc_y == "High-Income",]



elected.lis.p <- summary(elected.lis)$coefficients["factor(affcat)5",4] 

data.lis.temp$affcat <- 1
elected.lis.pred.1 <- mean(predict(elected.lis, data.lis.temp, re.form=NULL, type = "response")) 
data.lis.temp$affcat <- 5
elected.lis.pred.5 <- mean(predict(elected.lis, data.lis.temp, re.form=NULL, type = "response")) 
elected.lis.eff <- elected.lis.pred.5 - elected.lis.pred.1


elected.mis.p <- summary(elected.mis)$coefficients["factor(affcat)5",4] 

data.mis.temp$affcat <- 1
elected.mis.pred.1 <- mean(predict(elected.mis, data.mis.temp, re.form=NULL, type = "response")) 
data.mis.temp$affcat <- 5
elected.mis.pred.5 <- mean(predict(elected.mis, data.mis.temp, re.form=NULL, type = "response")) 
elected.mis.eff <- elected.mis.pred.5 - elected.mis.pred.1


elected.his.p <- summary(elected.his)$coefficients["factor(affcat)5",4] 

data.his.temp$affcat <- 1
elected.his.pred.1 <- mean(predict(elected.his, data.his.temp, re.form=NULL, type = "response")) 
data.his.temp$affcat <- 5
elected.his.pred.5 <- mean(predict(elected.his, data.his.temp, re.form=NULL, type = "response")) 
elected.his.eff <- elected.his.pred.5 - elected.his.pred.1




##################################
# Leader of Student Organization #
##################################

table(small$orglead01) #all missing for these years 


# Low-Income

orglead.lis <- glmer(orglead01 ~ commlead_tfs + factor(affcat) + hitestscore_y + testscore_na +  female_y +  asian_y +  hispanic_y + black_y +  othrace_y +
                       jewish_y +  catholic_y + evangelical_y + otherornorelig_y + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                       businesstfs + makemoneyvimp_y +  hitestscoreper_y + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                       hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                       makemoneyvimpper_y +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS_y) + (1 | ACERECODE) + (1 | ace_year),
                     family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                     data = small[small$csstaken ==1 & small$parinc_y == "Low-Income",], weights=(weights_level2))  


# Middle-Income

orglead.mis <- glmer(orglead01 ~ commlead_tfs + factor(affcat) + hitestscore_y + testscore_na +  female_y +  asian_y +  hispanic_y + black_y +  othrace_y +
                       jewish_y +  catholic_y + evangelical_y + otherornorelig_y + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                       businesstfs + makemoneyvimp_y +  hitestscoreper_y + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                       hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                       makemoneyvimpper_y +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS_y) + (1 | ACERECODE) + (1 | ace_year),
                     family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                     data = small[small$csstaken ==1 & small$parinc_y == "Middle-Income",], weights=(weights_level2))   


# High-Income

orglead.his <- glmer(orglead01 ~ commlead_tfs + factor(affcat) + hitestscore_y + testscore_na +  female_y +  asian_y +  hispanic_y + black_y +  othrace_y +
                       jewish_y +  catholic_y + evangelical_y + otherornorelig_y + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                       businesstfs + makemoneyvimp_y +  hitestscoreper_y + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                       hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                       makemoneyvimpper_y +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS_y) + (1 | ACERECODE) + (1 | ace_year),
                     family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                     data = small[small$csstaken ==1 & small$parinc_y == "High-Income",], weights=(weights_level2))  



modelvars <- c("orglead01", "commlead_tfs", "affcat", "hitestscore_y", "female_y", "asian_y", "hispanic_y", "black_y", "othrace_y",
               "jewish_y", "catholic_y", "evangelical_y", "otherornorelig_y", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs", "makemoneyvimp_y",  "hitestscoreper_y",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper_y", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south", "YEAR_TFS_y", "ACERECODE", "ace_year", "csstaken", "weights_level2", "parinc_y")


small2 <- small[complete.cases(small[,modelvars]),]

data.lis.temp  <- small2[small2$csstaken ==1 & small2$parinc_y == "Low-Income",]
data.mis.temp  <- small2[small2$csstaken ==1 & small2$parinc_y == "Middle-Income",]
data.his.temp  <- small2[small2$csstaken ==1 & small2$parinc_y == "High-Income",]


orglead.lis.p <- summary(orglead.lis)$coefficients["factor(affcat)5",4] 

data.lis.temp$affcat <- 1
orglead.lis.pred.1 <- mean(predict(orglead.lis, data.lis.temp, re.form=NULL, type = "response")) 
data.lis.temp$affcat <- 5
orglead.lis.pred.5 <- mean(predict(orglead.lis, data.lis.temp, re.form=NULL, type = "response")) 
orglead.lis.eff <- orglead.lis.pred.5 - orglead.lis.pred.1


orglead.mis.p <- summary(orglead.mis)$coefficients["factor(affcat)5",4] 

data.mis.temp$affcat <- 1
orglead.mis.pred.1 <- mean(predict(orglead.mis, data.mis.temp, re.form=NULL, type = "response")) 
data.mis.temp$affcat <- 5
orglead.mis.pred.5 <- mean(predict(orglead.mis, data.mis.temp, re.form=NULL, type = "response")) 
orglead.mis.eff <- orglead.mis.pred.5 - orglead.mis.pred.1


orglead.his.p <- summary(orglead.his)$coefficients["factor(affcat)5",4] 

data.his.temp$affcat <- 1
orglead.his.pred.1 <- mean(predict(orglead.his, data.his.temp, re.form=NULL, type = "response")) 
data.his.temp$affcat <- 5
orglead.his.pred.5 <- mean(predict(orglead.his, data.his.temp, re.form=NULL, type = "response")) 
orglead.his.eff <- orglead.his.pred.5 - orglead.his.pred.1



########################################
# Protest Index 
#########################################

table(small$protestindex_css)
table(small$protest_tfs)

# Low-Income

protest.lis <- glmer(protestindex_css ~ protest_tfs + factor(affcat) + hitestscore_y + testscore_na +  female_y +  asian_y +  hispanic_y + black_y +  othrace_y +
                       jewish_y +  catholic_y + evangelical_y + otherornorelig_y + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                       businesstfs + makemoneyvimp_y +  hitestscoreper_y + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                       hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                       makemoneyvimpper_y +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS_y) + (1 | ACERECODE) + (1 | ace_year),
                     family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                     data = small[small$csstaken ==1 & small$parinc_y == "Low-Income",], weights=(weights_level2))


# Middle-Income

protest.mis <- glmer(protestindex_css ~ protest_tfs + factor(affcat) + hitestscore_y + testscore_na +  female_y +  asian_y +  hispanic_y + black_y +  othrace_y +
                       jewish_y +  catholic_y + evangelical_y + otherornorelig_y + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                       businesstfs + makemoneyvimp_y +  hitestscoreper_y + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                       hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                       makemoneyvimpper_y +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS_y) + (1 | ACERECODE) + (1 | ace_year),
                     family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                     data = small[small$csstaken ==1 & small$parinc_y == "Middle-Income",], weights=(weights_level2)) 


# High-Income

protest.his <- glmer(protestindex_css ~ protest_tfs + factor(affcat) + hitestscore_y + testscore_na +  female_y +  asian_y +  hispanic_y + black_y +  othrace_y +
                       jewish_y +  catholic_y + evangelical_y + otherornorelig_y + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                       businesstfs + makemoneyvimp_y +  hitestscoreper_y + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                       hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                       makemoneyvimpper_y +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS_y) + (1 | ACERECODE) + (1 | ace_year),
                     family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                     data = small[small$csstaken ==1 & small$parinc_y == "High-Income",], weights=(weights_level2))  

summary(protest.lis)


modelvars <- c("protestindex_css", "protest_tfs", "affcat", "hitestscore_y", "female_y", "asian_y", "hispanic_y", "black_y", "othrace_y",
               "jewish_y", "catholic_y", "evangelical_y", "otherornorelig_y", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs", "makemoneyvimp_y",  "hitestscoreper_y",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper_y", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south", "YEAR_TFS_y", "ACERECODE", "ace_year", "csstaken", "weights_level2", "parinc_y")


small2 <- small[complete.cases(small[,modelvars]),]

data.lis.temp  <- small2[small2$csstaken ==1 & small2$parinc_y == "Low-Income",]
data.mis.temp  <- small2[small2$csstaken ==1 & small2$parinc_y == "Middle-Income",]
data.his.temp  <- small2[small2$csstaken ==1 & small2$parinc_y == "High-Income",]

protest.lis.p <- summary(protest.lis)$coefficients["factor(affcat)5",4] 

data.lis.temp$affcat <- 1
protest.lis.pred.1 <- mean(predict(protest.lis, data.lis.temp, re.form=NULL, type = "response")) 
data.lis.temp$affcat <- 5
protest.lis.pred.5 <- mean(predict(protest.lis, data.lis.temp, re.form=NULL, type = "response")) 
protest.lis.eff <- protest.lis.pred.5 - protest.lis.pred.1


protest.mis.p <- summary(protest.mis)$coefficients["factor(affcat)5",4] 

data.mis.temp$affcat <- 1
protest.mis.pred.1 <- mean(predict(protest.mis, data.mis.temp, re.form=NULL, type = "response")) 
data.mis.temp$affcat <- 5
protest.mis.pred.5 <- mean(predict(protest.mis, data.mis.temp, re.form=NULL, type = "response")) 
protest.mis.eff <- protest.mis.pred.5 - protest.mis.pred.1


protest.his.p <- summary(protest.his)$coefficients["factor(affcat)5",4] 

data.his.temp$affcat <- 1
protest.his.pred.1 <- mean(predict(protest.his, data.his.temp, re.form=NULL, type = "response")) 
data.his.temp$affcat <- 5
protest.his.pred.5 <- mean(predict(protest.his, data.his.temp, re.form=NULL, type = "response")) 
protest.his.eff <- protest.his.pred.5 - protest.his.pred.1





#################################
# Create Predicted Effects Plot #
#################################

data = data.frame (variable = c("Protest Involvement", "Protest Involvement", "Protest Involvement",
                                 "Passive Engagement Index", "Passive Engagement Index", "Passive Engagement Index",
                                 "Vote in National Election", "Vote in National Election", "Vote in National Election",
                                 "Participate in Campaign", "Participate in Campaign", "Participate in Campaign",
                                 "Elected to Student Government", "Elected to Student Government", "Elected to Student Government"),
                    parinc= c("Low",
                              "Middle",
                              "High"),
                    effect = c(protest.lis.eff, protest.mis.eff, protest.his.eff,
                               passive.lis.eff, passive.mis.eff, passive.his.eff,
                               voteprez.lis.eff, voteprez.mis.eff, voteprez.his.eff,
                               campaign.lis.eff, campaign.mis.eff, campaign.his.eff,
                               elected.lis.eff, elected.mis.eff, elected.his.eff),
                    sig = c(protest.lis.p, protest.mis.p, protest.his.p,
                            passive.lis.p, passive.mis.p, passive.his.p,
                            voteprez.lis.p, voteprez.mis.p, voteprez.his.p,
                            campaign.lis.p, campaign.mis.p, campaign.his.p,
                            elected.lis.p, elected.mis.p, elected.his.p)) 


data$sig <- ifelse(data$sig >= .05, "n.s.",
                   ifelse(data$sig < .05 &
                            data$sig >= .01, "*",
                          ifelse(data$sig < .01 &
                                   data$sig >= .001, "**",
                                 ifelse(data$sig < .001, "***", NA))))


data$variable <- factor(data$variable, levels = c("Protest Involvement",
                                                  "Passive Engagement Index",
                                                  "Vote in National Election",
                                                  "Participate in Campaign",
                                                  "Elected to Student Government"))

p1 <- ggplot(data[1:6,], aes(x=parinc, y=effect*100, fill=parinc)) +
  facet_grid(.~variable) +
  geom_bar(stat="identity") +
  ylab("Percent Point Effect") +
  xlab("Parental Income") +
  guides(fill=FALSE) +
  theme_bw() +
  theme(text = element_text(size=22)) +
  geom_hline(yintercept=0, linetype = "dashed") +
  scale_y_continuous(limits=c(-5,15)) +
  geom_text(aes(x=parinc, y=ifelse(sig=="n.s.", .8, .4), 
                label=sig), 
            position = position_dodge(width=1)) 

p2 <- ggplot(data[7:15,], aes(x=parinc, y=effect*100, fill=parinc)) +
  facet_grid(.~variable) +
  geom_bar(stat="identity") +
  ylab("Percent Point Effect") +
  xlab("Parental Income") +
  guides(fill=FALSE) +
  theme_bw() +
  theme(text = element_text(size=22)) +
  geom_hline(yintercept=0, linetype = "dashed") +
  scale_y_continuous(limits=c(-20,21)) +
  geom_text(aes(x=parinc, y=ifelse(sig=="n.s.", .8, .4), 
                label=sig), 
            position = position_dodge(width=1)) 

grid.arrange(p1, p2)







#########################
# Level 2 by subgroup, Small #
#########################



describe(small$weights_level2)

passive.lis2 <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + factor(affcat) + hitestscore_y + testscore_na +  female_y +  asian_y +  hispanic_y + black_y +  othrace_y +
                       jewish_y +  catholic_y + evangelical_y + otherornorelig_y + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                       businesstfs + makemoneyvimp_y +  hitestscoreper_y + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                       hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                       makemoneyvimpper_y +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS_y) + (1 | ACERECODE) + (1 | ace_year),
                     data = small[small$csstaken ==1 & small$parinc_y == "Low-Income",], weights=(weights_level2_lis))  


passive.mis2 <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + factor(affcat) + hitestscore_y + testscore_na +  female_y +  asian_y +  hispanic_y + black_y +  othrace_y +
                       jewish_y +  catholic_y + evangelical_y + otherornorelig_y + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                       businesstfs + makemoneyvimp_y +  hitestscoreper_y + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                       hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                       makemoneyvimpper_y +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS_y) + (1 | ACERECODE) + (1 | ace_year),
                     data = small[small$csstaken ==1 & small$parinc_y == "Middle-Income",], weights=(weights_level2_mis))  


passive.his2 <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + factor(affcat) + hitestscore_y + testscore_na +  female_y +  asian_y +  hispanic_y + black_y +  othrace_y +
                       jewish_y +  catholic_y + evangelical_y + otherornorelig_y + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                       businesstfs + makemoneyvimp_y +  hitestscoreper_y + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                       hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                       makemoneyvimpper_y +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS_y) + (1 | ACERECODE) + (1 | ace_year),
                     data = small[small$csstaken ==1 & small$parinc_y == "High-Income",], weights=(weights_level2_his))  

summary(passive.lis2)
summary(passive.mis2)
summary(passive.his2)


modelvars <- c("passive_index_css_avg", "passive_index_tfs_avg", "affcat", "hitestscore_y", "female_y", "asian_y", "hispanic_y", "black_y", "othrace_y",
               "jewish_y", "catholic_y", "evangelical_y", "otherornorelig_y", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs", "makemoneyvimp_y",  "hitestscoreper_y",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper_y", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south", "YEAR_TFS_y", "ACERECODE", "ace_year", "csstaken", "parinc_y")

small2 <- small[complete.cases(small[,modelvars]),]

data.lis.temp  <- small2[small2$csstaken ==1 & small2$parinc_y == "Low-Income" & !is.na(small2$weights_level2_lis),]
data.mis.temp  <- small2[small2$csstaken ==1 & small2$parinc_y == "Middle-Income" & !is.na(small2$weights_level2_mis),]
data.his.temp  <- small2[small2$csstaken ==1 & small2$parinc_y == "High-Income" & !is.na(small2$weights_level2_his),]



passive.lis2.p <- summary(passive.lis2)$coefficients["factor(affcat)5", 5] 


data.lis.temp$affcat <- 1
passive.lis2.pred.1 <- mean(predict(passive.lis2, data.lis.temp, re.form=NULL)) 
data.lis.temp$affcat <- 5
passive.lis2.pred.5 <- mean(predict(passive.lis2, data.lis.temp, re.form=NULL)) 
passive.lis2.eff <- passive.lis2.pred.5 - passive.lis2.pred.1

passive.mis2.p <- summary(passive.mis2)$coefficients["factor(affcat)5",5] 

data.mis.temp$affcat <- 1
passive.mis2.pred.1 <- mean(predict(passive.mis2, data.mis.temp, re.form=NULL)) 
data.mis.temp$affcat <- 5
passive.mis2.pred.5 <- mean(predict(passive.mis2, data.mis.temp, re.form=NULL)) 
passive.mis2.eff <- passive.mis2.pred.5 - passive.mis2.pred.1

passive.his2.p <- summary(passive.his2)$coefficients["factor(affcat)5",5] 

data.his.temp$affcat <- 1
passive.his2.pred.1 <- mean(predict(passive.his2, data.his.temp, re.form=NULL)) 
data.his.temp$affcat <- 5
passive.his2.pred.5 <- mean(predict(passive.his2, data.his.temp, re.form=NULL)) 
passive.his2.eff <- passive.his2.pred.5 - passive.his2.pred.1



##########
# Voting #
##########


table(small$voteprez2)
table(small$polaffairs_tfs)


voteprez.lis2 <- glmer(voteprez2 ~ polaffairs_tfs +  factor(affcat) + hitestscore_y + testscore_na +  female_y +  asian_y +  hispanic_y + black_y +  othrace_y +
                         jewish_y +  catholic_y + evangelical_y + otherornorelig_y + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                         businesstfs + makemoneyvimp_y +  hitestscoreper_y + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                         hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                         makemoneyvimpper_y +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS_y) + (1 | ACERECODE) + (1 | ace_year),
                       family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                       data = small[small$csstaken ==1 & small$parinc_y == "Low-Income",], weights=(weights_level2_lis))  




voteprez.mis2 <- glmer(voteprez2 ~ polaffairs_tfs +  factor(affcat) + hitestscore_y + testscore_na +  female_y +  asian_y +  hispanic_y + black_y +  othrace_y +
                         jewish_y +  catholic_y + evangelical_y + otherornorelig_y + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                         businesstfs + makemoneyvimp_y +  hitestscoreper_y + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                         hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                         makemoneyvimpper_y +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS_y) + (1 | ACERECODE) + (1 | ace_year),
                       family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                       data = small[small$csstaken ==1 & small$parinc_y == "Middle-Income",], weights=(weights_level2_mis))  


voteprez.his2 <- glmer(voteprez2 ~ polaffairs_tfs +  factor(affcat) + hitestscore_y + testscore_na +  female_y +  asian_y +  hispanic_y + black_y +  othrace_y +
                         jewish_y +  catholic_y + evangelical_y + otherornorelig_y + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                         businesstfs + makemoneyvimp_y +  hitestscoreper_y + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                         hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                         makemoneyvimpper_y +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS_y) + (1 | ACERECODE) + (1 | ace_year),
                       family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                       data = small[small$csstaken ==1 & small$parinc_y == "High-Income",], weights=(weights_level2_his))  


modelvars <- c("voteprez2", "polaffairs_tfs", "affcat", "hitestscore_y", "female_y", "asian_y", "hispanic_y", "black_y", "othrace_y",
               "jewish_y", "catholic_y", "evangelical_y", "otherornorelig_y", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs", "makemoneyvimp_y",  "hitestscoreper_y",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper_y", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south", "YEAR_TFS_y", "ACERECODE", "ace_year", "csstaken", "parinc_y")


small2 <- small[complete.cases(small[,modelvars]),]

data.lis.temp  <- small2[small2$csstaken ==1 & small2$parinc_y == "Low-Income" & !is.na(small2$weights_level2_lis),]
data.mis.temp  <- small2[small2$csstaken ==1 & small2$parinc_y == "Middle-Income" & !is.na(small2$weights_level2_mis),]
data.his.temp  <- small2[small2$csstaken ==1 & small2$parinc_y == "High-Income" & !is.na(small2$weights_level2_his),]



voteprez.lis2.p <- summary(voteprez.lis2)$coefficients["factor(affcat)5",4] 

data.lis.temp$affcat <- 1
voteprez.lis2.pred.1 <- mean(predict(voteprez.lis2, data.lis.temp, re.form=NULL, type = "response")) 
data.lis.temp$affcat <- 5
voteprez.lis2.pred.5 <- mean(predict(voteprez.lis2, data.lis.temp, re.form=NULL, type = "response")) 
voteprez.lis2.eff <- voteprez.lis2.pred.5 - voteprez.lis2.pred.1



voteprez.mis2.p <- summary(voteprez.mis2)$coefficients["factor(affcat)5",4] 

data.mis.temp$affcat <- 1
voteprez.mis2.pred.1 <- mean(predict(voteprez.mis2, data.mis.temp, re.form=NULL, type = "response")) 
data.mis.temp$affcat <- 5
voteprez.mis2.pred.5 <- mean(predict(voteprez.mis2, data.mis.temp, re.form=NULL, type = "response")) 
voteprez.mis2.eff <- voteprez.mis2.pred.5 - voteprez.mis2.pred.1


voteprez.his2.p <- summary(voteprez.his2)$coefficients["factor(affcat)5",4] 

data.his.temp$affcat <- 1
voteprez.his2.pred.1 <- mean(predict(voteprez.his2, data.his.temp, re.form=NULL, type = "response")) 
data.his.temp$affcat <- 5
voteprez.his2.pred.5 <- mean(predict(voteprez.his2, data.his.temp, re.form=NULL, type = "response")) 
voteprez.his2.eff <- voteprez.his2.pred.5 - voteprez.his2.pred.1



###############
# Campaigning #
###############

table(small$campaign_css)
table(small$campaign_tfs)


campaign.lis2 <- glmer(campaign_css ~ campaign_tfs + factor(affcat) + hitestscore_y + testscore_na +  female_y +  asian_y +  hispanic_y + black_y +  othrace_y +
                         jewish_y +  catholic_y + evangelical_y + otherornorelig_y + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                         businesstfs + makemoneyvimp_y +  hitestscoreper_y + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                         hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                         makemoneyvimpper_y +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS_y) + (1 | ACERECODE) + (1 | ace_year),
                       family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                       data = small[small$csstaken ==1 & small$parinc_y == "Low-Income",], weights=(weights_level2_lis))  


# Middle-Income

campaign.mis2 <- glmer(campaign_css ~ campaign_tfs + factor(affcat) + hitestscore_y + testscore_na +  female_y +  asian_y +  hispanic_y + black_y +  othrace_y +
                         jewish_y +  catholic_y + evangelical_y + otherornorelig_y + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                         businesstfs + makemoneyvimp_y +  hitestscoreper_y + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                         hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                         makemoneyvimpper_y +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS_y) + (1 | ACERECODE) + (1 | ace_year),
                       family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                       data = small[small$csstaken ==1 & small$parinc_y == "Middle-Income",], weights=(weights_level2_mis))  


# High-Income

campaign.his2 <- glmer(campaign_css ~ campaign_tfs + factor(affcat) + hitestscore_y + testscore_na +  female_y +  asian_y +  hispanic_y + black_y +  othrace_y +
                         jewish_y +  catholic_y + evangelical_y + otherornorelig_y + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                         businesstfs + makemoneyvimp_y +  hitestscoreper_y + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                         hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                         makemoneyvimpper_y +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS_y) + (1 | ACERECODE) + (1 | ace_year),
                       family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                       data = small[small$csstaken ==1 & small$parinc_y == "High-Income",], weights=(weights_level2_his))  



modelvars <- c("campaign_css", "campaign_tfs", "affcat", "hitestscore_y", "female_y", "asian_y", "hispanic_y", "black_y", "othrace_y",
               "jewish_y", "catholic_y", "evangelical_y", "otherornorelig_y", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs", "makemoneyvimp_y",  "hitestscoreper_y",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper_y", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south", "YEAR_TFS_y", "ACERECODE", "ace_year", "csstaken", "parinc_y")


small2 <- small[complete.cases(small[,modelvars]),]

data.lis.temp  <- small2[small2$csstaken ==1 & small2$parinc_y == "Low-Income" & !is.na(small2$weights_level2_lis),]
data.mis.temp  <- small2[small2$csstaken ==1 & small2$parinc_y == "Middle-Income" & !is.na(small2$weights_level2_mis),]
data.his.temp  <- small2[small2$csstaken ==1 & small2$parinc_y == "High-Income" & !is.na(small2$weights_level2_his),]



campaign.lis2.p <- summary(campaign.lis2)$coefficients["factor(affcat)5",4] 

data.lis.temp$affcat <- 1
campaign.lis2.pred.1 <- mean(predict(campaign.lis2, data.lis.temp, re.form=NULL, type = "response")) 
data.lis.temp$affcat <- 5
campaign.lis2.pred.5 <- mean(predict(campaign.lis2, data.lis.temp, re.form=NULL, type = "response")) 
campaign.lis2.eff <- campaign.lis2.pred.5 - campaign.lis2.pred.1


campaign.mis2.p <- summary(campaign.mis2)$coefficients["factor(affcat)5",4] 

data.mis.temp$affcat <- 1
campaign.mis2.pred.1 <- mean(predict(campaign.mis2, data.mis.temp, re.form=NULL, type = "response")) 
data.mis.temp$affcat <- 5
campaign.mis2.pred.5 <- mean(predict(campaign.mis2, data.mis.temp, re.form=NULL, type = "response")) 
campaign.mis2.eff <- campaign.mis2.pred.5 - campaign.mis2.pred.1


campaign.his2.p <- summary(campaign.his2)$coefficients["factor(affcat)5",4] 

data.his.temp$affcat <- 1
campaign.his2.pred.1 <- mean(predict(campaign.his2, data.his.temp, re.form=NULL, type = "response")) 
data.his.temp$affcat <- 5
campaign.his2.pred.5 <- mean(predict(campaign.his2, data.his.temp, re.form=NULL, type = "response")) 
campaign.his2.eff <- campaign.his2.pred.5 - campaign.his2.pred.1



#############################
# Elected to Student Office #
#############################

table(small$elected01_gov)
table(small$commlead_tfs)

elected.lis2 <- glmer(elected01_gov ~ commlead_tfs + factor(affcat) + hitestscore_y + testscore_na +  female_y +  asian_y +  hispanic_y + black_y +  othrace_y +
                        jewish_y +  catholic_y + evangelical_y + otherornorelig_y + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                        businesstfs + makemoneyvimp_y +  hitestscoreper_y + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                        hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                        makemoneyvimpper_y +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS_y) + (1 | ACERECODE) + (1 | ace_year),
                      family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                      data = small[small$csstaken ==1 & small$parinc_y == "Low-Income",], weights=(weights_level2_lis))  



# Middle-Income

elected.mis2 <- glmer(elected01_gov ~ commlead_tfs + factor(affcat) + hitestscore_y + testscore_na +  female_y +  asian_y +  hispanic_y + black_y +  othrace_y +
                        jewish_y +  catholic_y + evangelical_y + otherornorelig_y + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                        businesstfs + makemoneyvimp_y +  hitestscoreper_y + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                        hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                        makemoneyvimpper_y +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS_y) + (1 | ACERECODE) + (1 | ace_year),
                      family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                      data = small[small$csstaken ==1 & small$parinc_y == "Middle-Income",], weights=(weights_level2_mis))  



# High-Income

elected.his2 <- glmer(elected01_gov ~ commlead_tfs + factor(affcat) + hitestscore_y + testscore_na +  female_y +  asian_y +  hispanic_y + black_y +  othrace_y +
                        jewish_y +  catholic_y + evangelical_y + otherornorelig_y + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                        businesstfs + makemoneyvimp_y +  hitestscoreper_y + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                        hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                        makemoneyvimpper_y +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS_y) + (1 | ACERECODE) + (1 | ace_year),
                      family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                      data = small[small$csstaken ==1 & small$parinc_y == "High-Income",], weights=(weights_level2_his))  



modelvars <- c("elected01_gov", "commlead_tfs", "affcat", "hitestscore_y", "female_y", "asian_y", "hispanic_y", "black_y", "othrace_y",
               "jewish_y", "catholic_y", "evangelical_y", "otherornorelig_y", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs", "makemoneyvimp_y",  "hitestscoreper_y",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper_y", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south", "YEAR_TFS_y", "ACERECODE", "ace_year", "csstaken", "parinc_y")


small2 <- small[complete.cases(small[,modelvars]),]

data.lis.temp  <- small2[small2$csstaken ==1 & small2$parinc_y == "Low-Income" & !is.na(small2$weights_level2_lis),]
data.mis.temp  <- small2[small2$csstaken ==1 & small2$parinc_y == "Middle-Income" & !is.na(small2$weights_level2_mis),]
data.his.temp  <- small2[small2$csstaken ==1 & small2$parinc_y == "High-Income" & !is.na(small2$weights_level2_his),]




elected.lis2.p <- summary(elected.lis2)$coefficients["factor(affcat)5",4] 

data.lis.temp$affcat <- 1
elected.lis2.pred.1 <- mean(predict(elected.lis2, data.lis.temp, re.form=NULL, type = "response")) 
data.lis.temp$affcat <- 5
elected.lis2.pred.5 <- mean(predict(elected.lis2, data.lis.temp, re.form=NULL, type = "response")) 
elected.lis2.eff <- elected.lis2.pred.5 - elected.lis2.pred.1


elected.mis2.p <- summary(elected.mis2)$coefficients["factor(affcat)5",4] 

data.mis.temp$affcat <- 1
elected.mis2.pred.1 <- mean(predict(elected.mis2, data.mis.temp, re.form=NULL, type = "response")) 
data.mis.temp$affcat <- 5
elected.mis2.pred.5 <- mean(predict(elected.mis2, data.mis.temp, re.form=NULL, type = "response")) 
elected.mis2.eff <- elected.mis2.pred.5 - elected.mis2.pred.1


elected.his2.p <- summary(elected.his2)$coefficients["factor(affcat)5",4] 

data.his.temp$affcat <- 1
elected.his2.pred.1 <- mean(predict(elected.his2, data.his.temp, re.form=NULL, type = "response")) 
data.his.temp$affcat <- 5
elected.his2.pred.5 <- mean(predict(elected.his2, data.his.temp, re.form=NULL, type = "response")) 
elected.his2.eff <- elected.his2.pred.5 - elected.his2.pred.1


########################################
# Protest Index 
#########################################

table(small$protestindex_css)
table(small$protest_tfs)

# Low-Income

protest.lis2 <- glmer(protestindex_css ~ protest_tfs + factor(affcat) + hitestscore_y + testscore_na +  female_y +  asian_y +  hispanic_y + black_y +  othrace_y +
                        jewish_y +  catholic_y + evangelical_y + otherornorelig_y + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                        businesstfs + makemoneyvimp_y +  hitestscoreper_y + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                        hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                        makemoneyvimpper_y +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS_y) + (1 | ACERECODE) + (1 | ace_year),
                      family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                      data = small[small$csstaken ==1 & small$parinc_y == "Low-Income",], weights=(weights_level2_lis))


# Middle-Income

protest.mis2 <- glmer(protestindex_css ~ protest_tfs + factor(affcat) + hitestscore_y + testscore_na +  female_y +  asian_y +  hispanic_y + black_y +  othrace_y +
                        jewish_y +  catholic_y + evangelical_y + otherornorelig_y + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                        businesstfs + makemoneyvimp_y +  hitestscoreper_y + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                        hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                        makemoneyvimpper_y +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS_y) + (1 | ACERECODE) + (1 | ace_year),
                      family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                      data = small[small$csstaken ==1 & small$parinc_y == "Middle-Income",], weights=(weights_level2_mis)) 


# High-Income

protest.his2 <- glmer(protestindex_css ~ protest_tfs + factor(affcat) + hitestscore_y + testscore_na +  female_y +  asian_y +  hispanic_y + black_y +  othrace_y +
                        jewish_y +  catholic_y + evangelical_y + otherornorelig_y + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                        businesstfs + makemoneyvimp_y +  hitestscoreper_y + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                        hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                        makemoneyvimpper_y +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS_y) + (1 | ACERECODE) + (1 | ace_year),
                      family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                      data = small[small$csstaken ==1 & small$parinc_y == "High-Income",], weights=(weights_level2_his))  



modelvars <- c("protestindex_css", "protest_tfs", "affcat", "hitestscore_y", "female_y", "asian_y", "hispanic_y", "black_y", "othrace_y",
               "jewish_y", "catholic_y", "evangelical_y", "otherornorelig_y", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs", "makemoneyvimp_y",  "hitestscoreper_y",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper_y", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south", "YEAR_TFS_y", "ACERECODE", "ace_year", "csstaken", "parinc_y")


small2 <- small[complete.cases(small[,modelvars]),]

data.lis.temp  <- small2[small2$csstaken ==1 & small2$parinc_y == "Low-Income" & !is.na(small2$weights_level2_lis),]
data.mis.temp  <- small2[small2$csstaken ==1 & small2$parinc_y == "Middle-Income" & !is.na(small2$weights_level2_mis),]
data.his.temp  <- small2[small2$csstaken ==1 & small2$parinc_y == "High-Income" & !is.na(small2$weights_level2_his),]

protest.lis2.p <- summary(protest.lis2)$coefficients["factor(affcat)5",4] 

data.lis.temp$affcat <- 1
protest.lis2.pred.1 <- mean(predict(protest.lis2, data.lis.temp, re.form=NULL, type = "response")) 
data.lis.temp$affcat <- 5
protest.lis2.pred.5 <- mean(predict(protest.lis2, data.lis.temp, re.form=NULL, type = "response")) 
protest.lis2.eff <- protest.lis2.pred.5 - protest.lis2.pred.1


protest.mis2.p <- summary(protest.mis2)$coefficients["factor(affcat)5",4] 

data.mis.temp$affcat <- 1
protest.mis2.pred.1 <- mean(predict(protest.mis2, data.mis.temp, re.form=NULL, type = "response")) 
data.mis.temp$affcat <- 5
protest.mis2.pred.5 <- mean(predict(protest.mis2, data.mis.temp, re.form=NULL, type = "response")) 
protest.mis2.eff <- protest.mis2.pred.5 - protest.mis2.pred.1


protest.his2.p <- summary(protest.his2)$coefficients["factor(affcat)5",4] 

data.his.temp$affcat <- 1
protest.his2.pred.1 <- mean(predict(protest.his2, data.his.temp, re.form=NULL, type = "response")) 
data.his.temp$affcat <- 5
protest.his2.pred.5 <- mean(predict(protest.his2, data.his.temp, re.form=NULL, type = "response")) 
protest.his2.eff <- protest.his2.pred.5 - protest.his2.pred.1





#################################
# Create Predicted Effects Plot #
#################################

data2 = data.frame (variable = c("Protest Involvement", "Protest Involvement", "Protest Involvement",
                                "Passive Engagement Index", "Passive Engagement Index", "Passive Engagement Index",
                                "Vote in National Election", "Vote in National Election", "Vote in National Election",
                                "Participate in Campaign", "Participate in Campaign", "Participate in Campaign",
                                "Elected to Student Government", "Elected to Student Government", "Elected to Student Government"),
                   parinc= c("Low",
                             "Middle",
                             "High"),
                   effect = c(protest.lis2.eff, protest.mis2.eff, protest.his2.eff,
                              passive.lis2.eff, passive.mis2.eff, passive.his2.eff,
                              voteprez.lis2.eff, voteprez.mis2.eff, voteprez.his2.eff,
                              campaign.lis2.eff, campaign.mis2.eff, campaign.his2.eff,
                              elected.lis2.eff, elected.mis2.eff, elected.his2.eff),
                   sig = c(protest.lis2.p, protest.mis2.p, protest.his2.p,
                           passive.lis2.p, passive.mis2.p, passive.his2.p,
                           voteprez.lis2.p, voteprez.mis2.p, voteprez.his2.p,
                           campaign.lis2.p, campaign.mis2.p, campaign.his2.p,
                           elected.lis2.p, elected.mis2.p, elected.his2.p)) 


data2$sig <- ifelse(data2$sig >= .05, "n.s.",
                   ifelse(data2$sig < .05 &
                            data2$sig >= .01, "*",
                          ifelse(data2$sig < .01 &
                                   data2$sig >= .001, "**",
                                 ifelse(data2$sig < .001, "***", NA))))


data2$variable <- factor(data2$variable, levels = c("Protest Involvement",
                                                  "Passive Engagement Index",
                                                  "Vote in National Election",
                                                  "Participate in Campaign",
                                                  "Elected to Student Government"))

p1 <- ggplot(data2[1:6,], aes(x=parinc, y=effect*100, fill=parinc)) +
  facet_grid(.~variable) +
  geom_bar(stat="identity") +
  ylab("Percent Point Effect") +
  xlab("Parental Income") +
  guides(fill=FALSE) +
  theme_bw() +
  theme(text = element_text(size=22)) +
  geom_hline(yintercept=0, linetype = "dashed") +
  scale_y_continuous(limits=c(-10,16)) +
  geom_text(aes(x=parinc, y=ifelse(sig=="n.s.", .8, .4), 
                label=sig), 
            position = position_dodge(width=1)) 

p2 <- ggplot(data2[7:15,], aes(x=parinc, y=effect*100, fill=parinc)) +
  facet_grid(.~variable) +
  geom_bar(stat="identity") +
  ylab("Percent Point Effect") +
  xlab("Parental Income") +
  guides(fill=FALSE) +
  theme_bw() +
  theme(text = element_text(size=22)) +
  geom_hline(yintercept=0, linetype = "dashed") +
  scale_y_continuous(limits=c(-20,20)) +
  geom_text(aes(x=parinc, y=ifelse(sig=="n.s.", .8, .4), 
                label=sig), 
            position = position_dodge(width=1)) 

grid.arrange(p1, p2)


#####################
# Appendix Figure 7 #
#####################


#################################
# Original Data, but restricted years to match weighting
################################


css <- csscohort

######################
# Passive Engagement #
######################

passive.lis3 <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + factor(affcat) + hitestscore + testscore_na +  female +  asian +  hispanic + black +  othrace +
                       jewish +  catholic + evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                       businesstfs + makemoneyvimp +  hitestscoreper + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                       hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                       makemoneyvimpper +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS) + (1 | ACERECODE) + (1 | ace_year),
                     data = css[css$YEAR_TFS <= 1999 & css$parinc == "Low-Income",])  


passive.mis3 <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + factor(affcat) + hitestscore + testscore_na +  female +  asian +  hispanic + black +  othrace +
                       jewish +  catholic + evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                       businesstfs + makemoneyvimp +  hitestscoreper + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                       hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                       makemoneyvimpper +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS) + (1 | ACERECODE) + (1 | ace_year),
                     data = css[css$YEAR_TFS <= 1999 & css$parinc == "Middle-Income",])  


passive.his3 <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + factor(affcat) + hitestscore + testscore_na +  female +  asian +  hispanic + black +  othrace +
                       jewish +  catholic + evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                       businesstfs + makemoneyvimp +  hitestscoreper + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                       hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                       makemoneyvimpper +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS) + (1 | ACERECODE) + (1 | ace_year),
                     data = css[css$YEAR_TFS <= 1999 & css$parinc == "High-Income",])  

summary(passive.lis3)
summary(passive.mis3)
summary(passive.his3)


modelvars <- c("passive_index_css_avg", "passive_index_tfs_avg", "affcat", "hitestscore", "female", "asian", "hispanic", "black", "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs", "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south", "YEAR_TFS", "ACERECODE", "ace_year", "parinc")


css2 <- css[complete.cases(css[,modelvars]),]

data.lis.temp  <- css2[css2$YEAR_TFS <= 1999 & css2$parinc == "Low-Income" ,]
data.mis.temp  <- css2[css2$YEAR_TFS <= 1999 & css2$parinc == "Middle-Income" ,]
data.his.temp  <- css2[css2$YEAR_TFS <= 1999 & css2$parinc == "High-Income" ,]


passive.lis3.p <- summary(passive.lis3)$coefficients["factor(affcat)5", 5] 


data.lis.temp$affcat <- 1
passive.lis3.pred.1 <- mean(predict(passive.lis3, data.lis.temp, re.form=NULL)) 
data.lis.temp$affcat <- 5
passive.lis3.pred.5 <- mean(predict(passive.lis3, data.lis.temp, re.form=NULL)) 
passive.lis3.eff <- passive.lis3.pred.5 - passive.lis3.pred.1

passive.mis3.p <- summary(passive.mis3)$coefficients["factor(affcat)5",5] 

data.mis.temp$affcat <- 1
passive.mis3.pred.1 <- mean(predict(passive.mis3, data.mis.temp, re.form=NULL)) 
data.mis.temp$affcat <- 5
passive.mis3.pred.5 <- mean(predict(passive.mis3, data.mis.temp, re.form=NULL)) 
passive.mis3.eff <- passive.mis3.pred.5 - passive.mis3.pred.1

passive.his3.p <- summary(passive.his3)$coefficients["factor(affcat)5",5] 

data.his.temp$affcat <- 1
passive.his3.pred.1 <- mean(predict(passive.his3, data.his.temp, re.form=NULL)) 
data.his.temp$affcat <- 5
passive.his3.pred.5 <- mean(predict(passive.his3, data.his.temp, re.form=NULL)) 
passive.his3.eff <- passive.his3.pred.5 - passive.his3.pred.1



##########
# Voting #
##########


table(css$voteprez2)
table(css$polaffairs_tfs)


voteprez.lis3 <- glmer(voteprez2 ~ polaffairs_tfs +  factor(affcat) + hitestscore + testscore_na +  female +  asian +  hispanic + black +  othrace +
                         jewish +  catholic + evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                         businesstfs + makemoneyvimp +  hitestscoreper + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                         hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                         makemoneyvimpper +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS) + (1 | ACERECODE) + (1 | ace_year),
                       family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                       data = css[css$YEAR_TFS <= 1999 & css$parinc == "Low-Income",])  




voteprez.mis3 <- glmer(voteprez2 ~ polaffairs_tfs +  factor(affcat) + hitestscore + testscore_na +  female +  asian +  hispanic + black +  othrace +
                         jewish +  catholic + evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                         businesstfs + makemoneyvimp +  hitestscoreper + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                         hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                         makemoneyvimpper +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS) + (1 | ACERECODE) + (1 | ace_year),
                       family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                       data = css[css$YEAR_TFS <= 1999 & css$parinc == "Middle-Income",])  


voteprez.his3 <- glmer(voteprez2 ~ polaffairs_tfs +  factor(affcat) + hitestscore + testscore_na +  female +  asian +  hispanic + black +  othrace +
                         jewish +  catholic + evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                         businesstfs + makemoneyvimp +  hitestscoreper + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                         hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                         makemoneyvimpper +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS) + (1 | ACERECODE) + (1 | ace_year),
                       family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                       data = css[css$YEAR_TFS <= 1999 & css$parinc == "High-Income",])  


modelvars <- c("voteprez2", "polaffairs_tfs", "affcat", "hitestscore", "female", "asian", "hispanic", "black", "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs", "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south", "YEAR_TFS", "ACERECODE", "ace_year", "parinc")


css2 <- css[complete.cases(css[,modelvars]),]

data.lis.temp  <- css2[css2$YEAR_TFS <= 1999 & css2$parinc == "Low-Income" ,]
data.mis.temp  <- css2[css2$YEAR_TFS <= 1999 & css2$parinc == "Middle-Income" ,]
data.his.temp  <- css2[css2$YEAR_TFS <= 1999 & css2$parinc == "High-Income" ,]



voteprez.lis3.p <- summary(voteprez.lis3)$coefficients["factor(affcat)5",4] 

data.lis.temp$affcat <- 1
voteprez.lis3.pred.1 <- mean(predict(voteprez.lis3, data.lis.temp, re.form=NULL, type = "response")) 
data.lis.temp$affcat <- 5
voteprez.lis3.pred.5 <- mean(predict(voteprez.lis3, data.lis.temp, re.form=NULL, type = "response")) 
voteprez.lis3.eff <- voteprez.lis3.pred.5 - voteprez.lis3.pred.1



voteprez.mis3.p <- summary(voteprez.mis3)$coefficients["factor(affcat)5",4] 

data.mis.temp$affcat <- 1
voteprez.mis3.pred.1 <- mean(predict(voteprez.mis3, data.mis.temp, re.form=NULL, type = "response")) 
data.mis.temp$affcat <- 5
voteprez.mis3.pred.5 <- mean(predict(voteprez.mis3, data.mis.temp, re.form=NULL, type = "response")) 
voteprez.mis3.eff <- voteprez.mis3.pred.5 - voteprez.mis3.pred.1


voteprez.his3.p <- summary(voteprez.his3)$coefficients["factor(affcat)5",4] 

data.his.temp$affcat <- 1
voteprez.his3.pred.1 <- mean(predict(voteprez.his3, data.his.temp, re.form=NULL, type = "response")) 
data.his.temp$affcat <- 5
voteprez.his3.pred.5 <- mean(predict(voteprez.his3, data.his.temp, re.form=NULL, type = "response")) 
voteprez.his3.eff <- voteprez.his3.pred.5 - voteprez.his3.pred.1



###############
# Campaigning #
###############

table(css$campaign_css)
table(css$campaign_tfs)


campaign.lis3 <- glmer(campaign_css ~ campaign_tfs + factor(affcat) + hitestscore + testscore_na +  female +  asian +  hispanic + black +  othrace +
                         jewish +  catholic + evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                         businesstfs + makemoneyvimp +  hitestscoreper + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                         hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                         makemoneyvimpper +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS) + (1 | ACERECODE) + (1 | ace_year),
                       family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                       data = css[css$YEAR_TFS <= 1999 & css$parinc == "Low-Income",])  


# Middle-Income

campaign.mis3 <- glmer(campaign_css ~ campaign_tfs + factor(affcat) + hitestscore + testscore_na +  female +  asian +  hispanic + black +  othrace +
                         jewish +  catholic + evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                         businesstfs + makemoneyvimp +  hitestscoreper + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                         hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                         makemoneyvimpper +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS) + (1 | ACERECODE) + (1 | ace_year),
                       family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                       data = css[css$YEAR_TFS <= 1999 & css$parinc == "Middle-Income",])  


# High-Income

campaign.his3 <- glmer(campaign_css ~ campaign_tfs + factor(affcat) + hitestscore + testscore_na +  female +  asian +  hispanic + black +  othrace +
                         jewish +  catholic + evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                         businesstfs + makemoneyvimp +  hitestscoreper + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                         hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                         makemoneyvimpper +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS) + (1 | ACERECODE) + (1 | ace_year),
                       family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                       data = css[css$YEAR_TFS <= 1999 & css$parinc == "High-Income",])  



modelvars <- c("campaign_css", "campaign_tfs", "affcat", "hitestscore", "female", "asian", "hispanic", "black", "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs", "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south", "YEAR_TFS", "ACERECODE", "ace_year", "parinc")


css2 <- css[complete.cases(css[,modelvars]),]

data.lis.temp  <- css2[css2$YEAR_TFS <= 1999 & css2$parinc == "Low-Income" ,]
data.mis.temp  <- css2[css2$YEAR_TFS <= 1999 & css2$parinc == "Middle-Income" ,]
data.his.temp  <- css2[css2$YEAR_TFS <= 1999 & css2$parinc == "High-Income" ,]




campaign.lis3.p <- summary(campaign.lis3)$coefficients["factor(affcat)5",4] 

data.lis.temp$affcat <- 1
campaign.lis3.pred.1 <- mean(predict(campaign.lis3, data.lis.temp, re.form=NULL, type = "response")) 
data.lis.temp$affcat <- 5
campaign.lis3.pred.5 <- mean(predict(campaign.lis3, data.lis.temp, re.form=NULL, type = "response")) 
campaign.lis3.eff <- campaign.lis3.pred.5 - campaign.lis3.pred.1


campaign.mis3.p <- summary(campaign.mis3)$coefficients["factor(affcat)5",4] 

data.mis.temp$affcat <- 1
campaign.mis3.pred.1 <- mean(predict(campaign.mis3, data.mis.temp, re.form=NULL, type = "response")) 
data.mis.temp$affcat <- 5
campaign.mis3.pred.5 <- mean(predict(campaign.mis3, data.mis.temp, re.form=NULL, type = "response")) 
campaign.mis3.eff <- campaign.mis3.pred.5 - campaign.mis3.pred.1


campaign.his3.p <- summary(campaign.his3)$coefficients["factor(affcat)5",4] 

data.his.temp$affcat <- 1
campaign.his3.pred.1 <- mean(predict(campaign.his3, data.his.temp, re.form=NULL, type = "response")) 
data.his.temp$affcat <- 5
campaign.his3.pred.5 <- mean(predict(campaign.his3, data.his.temp, re.form=NULL, type = "response")) 
campaign.his3.eff <- campaign.his3.pred.5 - campaign.his3.pred.1



#############################
# Elected to Student Office #
#############################

table(css$elected01_gov)
table(css$commlead_tfs)

elected.lis3 <- glmer(elected01_gov ~ commlead_tfs + factor(affcat) + hitestscore + testscore_na +  female +  asian +  hispanic + black +  othrace +
                        jewish +  catholic + evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                        businesstfs + makemoneyvimp +  hitestscoreper + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                        hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                        makemoneyvimpper +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS) + (1 | ACERECODE) + (1 | ace_year),
                      family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                      data = css[css$YEAR_TFS <= 1999 & css$parinc == "Low-Income",])  



# Middle-Income

elected.mis3 <- glmer(elected01_gov ~ commlead_tfs + factor(affcat) + hitestscore + testscore_na +  female +  asian +  hispanic + black +  othrace +
                        jewish +  catholic + evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                        businesstfs + makemoneyvimp +  hitestscoreper + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                        hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                        makemoneyvimpper +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS) + (1 | ACERECODE) + (1 | ace_year),
                      family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                      data = css[css$YEAR_TFS <= 1999 & css$parinc == "Middle-Income",])  



# High-Income

elected.his3 <- glmer(elected01_gov ~ commlead_tfs + factor(affcat) + hitestscore + testscore_na +  female +  asian +  hispanic + black +  othrace +
                        jewish +  catholic + evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                        businesstfs + makemoneyvimp +  hitestscoreper + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                        hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                        makemoneyvimpper +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS) + (1 | ACERECODE) + (1 | ace_year),
                      family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                      data = css[css$YEAR_TFS <= 1999 & css$parinc == "High-Income",])  



modelvars <- c("elected01_gov", "commlead_tfs", "affcat", "hitestscore", "female", "asian", "hispanic", "black", "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs", "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south", "YEAR_TFS", "ACERECODE", "ace_year", "parinc")


css2 <- css[complete.cases(css[,modelvars]),]

data.lis.temp  <- css2[css2$YEAR_TFS <= 1999 & css2$parinc == "Low-Income" ,]
data.mis.temp  <- css2[css2$YEAR_TFS <= 1999 & css2$parinc == "Middle-Income" ,]
data.his.temp  <- css2[css2$YEAR_TFS <= 1999 & css2$parinc == "High-Income" ,]





elected.lis3.p <- summary(elected.lis3)$coefficients["factor(affcat)5",4] 

data.lis.temp$affcat <- 1
elected.lis3.pred.1 <- mean(predict(elected.lis3, data.lis.temp, re.form=NULL, type = "response")) 
data.lis.temp$affcat <- 5
elected.lis3.pred.5 <- mean(predict(elected.lis3, data.lis.temp, re.form=NULL, type = "response")) 
elected.lis3.eff <- elected.lis3.pred.5 - elected.lis3.pred.1


elected.mis3.p <- summary(elected.mis3)$coefficients["factor(affcat)5",4] 

data.mis.temp$affcat <- 1
elected.mis3.pred.1 <- mean(predict(elected.mis3, data.mis.temp, re.form=NULL, type = "response")) 
data.mis.temp$affcat <- 5
elected.mis3.pred.5 <- mean(predict(elected.mis3, data.mis.temp, re.form=NULL, type = "response")) 
elected.mis3.eff <- elected.mis3.pred.5 - elected.mis3.pred.1


elected.his3.p <- summary(elected.his3)$coefficients["factor(affcat)5",4] 

data.his.temp$affcat <- 1
elected.his3.pred.1 <- mean(predict(elected.his3, data.his.temp, re.form=NULL, type = "response")) 
data.his.temp$affcat <- 5
elected.his3.pred.5 <- mean(predict(elected.his3, data.his.temp, re.form=NULL, type = "response")) 
elected.his3.eff <- elected.his3.pred.5 - elected.his3.pred.1




##################################
# Leader of Student Organization #
##################################

table(css$orglead01) #all missing for these years 


# Low-Income

orglead.lis <- glmer(orglead01 ~ commlead_tfs + factor(affcat) + hitestscore + testscore_na +  female +  asian +  hispanic + black +  othrace +
                       jewish +  catholic + evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                       businesstfs + makemoneyvimp +  hitestscoreper + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                       hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                       makemoneyvimpper +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS) + (1 | ACERECODE) + (1 | ace_year),
                     family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                     data = css[css$YEAR_TFS <= 1999 & css$parinc == "Low-Income",])  


# Middle-Income

orglead.mis <- glmer(orglead01 ~ commlead_tfs + factor(affcat) + hitestscore + testscore_na +  female +  asian +  hispanic + black +  othrace +
                       jewish +  catholic + evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                       businesstfs + makemoneyvimp +  hitestscoreper + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                       hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                       makemoneyvimpper +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS) + (1 | ACERECODE) + (1 | ace_year),
                     family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                     data = css[css$YEAR_TFS <= 1999 & css$parinc == "Middle-Income",])   


# High-Income

orglead.his <- glmer(orglead01 ~ commlead_tfs + factor(affcat) + hitestscore + testscore_na +  female +  asian +  hispanic + black +  othrace +
                       jewish +  catholic + evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                       businesstfs + makemoneyvimp +  hitestscoreper + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                       hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                       makemoneyvimpper +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS) + (1 | ACERECODE) + (1 | ace_year),
                     family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                     data = css[css$YEAR_TFS <= 1999 & css$parinc == "High-Income",])  



modelvars <- c("orglead01", "commlead_tfs", "affcat", "hitestscore", "female", "asian", "hispanic", "black", "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs", "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south", "YEAR_TFS", "ACERECODE", "ace_year", "csstaken", "parinc")


css2 <- css[complete.cases(css[,modelvars]),]

data.lis.temp  <- css2[css2$parinc == "Low-Income" ,]
data.mis.temp  <- css2[css2$parinc == "Middle-Income" ,]
data.his.temp  <- css2[css2$parinc == "High-Income" ,]



orglead.lis.p <- summary(orglead.lis)$coefficients["factor(affcat)5",4] 

data.lis.temp$affcat <- 1
orglead.lis.pred.1 <- mean(predict(orglead.lis, data.lis.temp, re.form=NULL, type = "response")) 
data.lis.temp$affcat <- 5
orglead.lis.pred.5 <- mean(predict(orglead.lis, data.lis.temp, re.form=NULL, type = "response")) 
orglead.lis.eff <- orglead.lis.pred.5 - orglead.lis.pred.1


orglead.mis.p <- summary(orglead.mis)$coefficients["factor(affcat)5",4] 

data.mis.temp$affcat <- 1
orglead.mis.pred.1 <- mean(predict(orglead.mis, data.mis.temp, re.form=NULL, type = "response")) 
data.mis.temp$affcat <- 5
orglead.mis.pred.5 <- mean(predict(orglead.mis, data.mis.temp, re.form=NULL, type = "response")) 
orglead.mis.eff <- orglead.mis.pred.5 - orglead.mis.pred.1


orglead.his.p <- summary(orglead.his)$coefficients["factor(affcat)5",4] 

data.his.temp$affcat <- 1
orglead.his.pred.1 <- mean(predict(orglead.his, data.his.temp, re.form=NULL, type = "response")) 
data.his.temp$affcat <- 5
orglead.his.pred.5 <- mean(predict(orglead.his, data.his.temp, re.form=NULL, type = "response")) 
orglead.his.eff <- orglead.his.pred.5 - orglead.his.pred.1



########################################
# Protest Index 
#########################################

table(css$protestindex_css)
table(css$protest_tfs)

# Low-Income

protest.lis3 <- glmer(protestindex_css ~ protest_tfs + factor(affcat) + hitestscore + testscore_na +  female +  asian +  hispanic + black +  othrace +
                        jewish +  catholic + evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                        businesstfs + makemoneyvimp +  hitestscoreper + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                        hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                        makemoneyvimpper +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS) + (1 | ACERECODE) + (1 | ace_year),
                      family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                      data = css[css$YEAR_TFS <= 1999 & css$parinc == "Low-Income",])


# Middle-Income

protest.mis3 <- glmer(protestindex_css ~ protest_tfs + factor(affcat) + hitestscore + testscore_na +  female +  asian +  hispanic + black +  othrace +
                        jewish +  catholic + evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                        businesstfs + makemoneyvimp +  hitestscoreper + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                        hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                        makemoneyvimpper +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS) + (1 | ACERECODE) + (1 | ace_year),
                      family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                      data = css[css$YEAR_TFS <= 1999 & css$parinc == "Middle-Income",]) 


# High-Income

protest.his3 <- glmer(protestindex_css ~ protest_tfs + factor(affcat) + hitestscore + testscore_na +  female +  asian +  hispanic + black +  othrace +
                        jewish +  catholic + evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                        businesstfs + makemoneyvimp +  hitestscoreper + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                        hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                        makemoneyvimpper +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS) + (1 | ACERECODE) + (1 | ace_year),
                      family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                      data = css[css$YEAR_TFS <= 1999 & css$parinc == "High-Income",])  



modelvars <- c("protestindex_css", "protest_tfs", "affcat", "hitestscore", "female", "asian", "hispanic", "black", "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs", "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south", "YEAR_TFS", "ACERECODE", "ace_year", "parinc")


css2 <- css[complete.cases(css[,modelvars]),]

data.lis.temp  <- css2[css2$YEAR_TFS <= 1999 & css2$parinc == "Low-Income" ,]
data.mis.temp  <- css2[css2$YEAR_TFS <= 1999 & css2$parinc == "Middle-Income" ,]
data.his.temp  <- css2[css2$YEAR_TFS <= 1999 & css2$parinc == "High-Income" ,]

protest.lis3.p <- summary(protest.lis3)$coefficients["factor(affcat)5",4] 

data.lis.temp$affcat <- 1
protest.lis3.pred.1 <- mean(predict(protest.lis3, data.lis.temp, re.form=NULL, type = "response")) 
data.lis.temp$affcat <- 5
protest.lis3.pred.5 <- mean(predict(protest.lis3, data.lis.temp, re.form=NULL, type = "response")) 
protest.lis3.eff <- protest.lis3.pred.5 - protest.lis3.pred.1


protest.mis3.p <- summary(protest.mis3)$coefficients["factor(affcat)5",4] 

data.mis.temp$affcat <- 1
protest.mis3.pred.1 <- mean(predict(protest.mis3, data.mis.temp, re.form=NULL, type = "response")) 
data.mis.temp$affcat <- 5
protest.mis3.pred.5 <- mean(predict(protest.mis3, data.mis.temp, re.form=NULL, type = "response")) 
protest.mis3.eff <- protest.mis3.pred.5 - protest.mis3.pred.1


protest.his3.p <- summary(protest.his3)$coefficients["factor(affcat)5",4] 

data.his.temp$affcat <- 1
protest.his3.pred.1 <- mean(predict(protest.his3, data.his.temp, re.form=NULL, type = "response")) 
data.his.temp$affcat <- 5
protest.his3.pred.5 <- mean(predict(protest.his3, data.his.temp, re.form=NULL, type = "response")) 
protest.his3.eff <- protest.his3.pred.5 - protest.his3.pred.1





#################################
# Create Predicted Effects Plot #
#################################

data3 = data.frame (variable = c("Protest Involvement", "Protest Involvement", "Protest Involvement",
                                 "Passive Engagement Index", "Passive Engagement Index", "Passive Engagement Index",
                                 "Vote in National Election", "Vote in National Election", "Vote in National Election",
                                 "Participate in Campaign", "Participate in Campaign", "Participate in Campaign",
                                 "Elected to Student Government", "Elected to Student Government", "Elected to Student Government"),
                    parinc= c("Low",
                              "Middle",
                              "High"),
                    effect = c(protest.lis3.eff, protest.mis3.eff, protest.his3.eff,
                               passive.lis3.eff, passive.mis3.eff, passive.his3.eff,
                               voteprez.lis3.eff, voteprez.mis3.eff, voteprez.his3.eff,
                               campaign.lis3.eff, campaign.mis3.eff, campaign.his3.eff,
                               elected.lis3.eff, elected.mis3.eff, elected.his3.eff),
                    sig = c(protest.lis3.p, protest.mis3.p, protest.his3.p,
                            passive.lis3.p, passive.mis3.p, passive.his3.p,
                            voteprez.lis3.p, voteprez.mis3.p, voteprez.his3.p,
                            campaign.lis3.p, campaign.mis3.p, campaign.his3.p,
                            elected.lis3.p, elected.mis3.p, elected.his3.p)) 



data3$sig <- ifelse(data3$sig >= .05, "n.s.",
                    ifelse(data3$sig < .05 &
                             data3$sig >= .01, "*",
                           ifelse(data3$sig < .01 &
                                    data3$sig >= .001, "**",
                                  ifelse(data3$sig < .001, "***", NA))))


data3$variable <- factor(data3$variable, levels = c("Protest Involvement",
                                                    "Passive Engagement Index",
                                                    "Vote in National Election",
                                                    "Participate in Campaign",
                                                    "Elected to Student Government"))

p1 <- ggplot(data3[1:6,], aes(x=parinc, y=effect*100, fill=parinc)) +
  facet_grid(.~variable) +
  geom_bar(stat="identity") +
  ylab("Percent Point Effect") +
  xlab("Parental Income") +
  guides(fill=FALSE) +
  theme_bw() +
  theme(text = element_text(size=22)) +
  geom_hline(yintercept=0, linetype = "dashed") +
  scale_y_continuous(limits=c(-10,16)) +
  geom_text(aes(x=parinc, y=ifelse(sig=="n.s.", .8, .4), 
                label=sig), 
            position = position_dodge(width=1)) 

p2 <- ggplot(data3[7:15,], aes(x=parinc, y=effect*100, fill=parinc)) +
  facet_grid(.~variable) +
  geom_bar(stat="identity") +
  ylab("Percent Point Effect") +
  xlab("Parental Income") +
  guides(fill=FALSE) +
  theme_bw() +
  theme(text = element_text(size=22)) +
  geom_hline(yintercept=0, linetype = "dashed") +
  scale_y_continuous(limits=c(-20,20)) +
  geom_text(aes(x=parinc, y=ifelse(sig=="n.s.", .8, .4), 
                label=sig), 
            position = position_dodge(width=1)) 

grid.arrange(p1, p2)

####################
# Appendix Table 7 #
####################

texreg(list(passive.lis, voteprez2.lis, campaign.lis, protest.lis, elected.lis, orglead.lis),
       caption = "The Effect of Campus Affluence on Political Participation", 
       custom.model.names = c("Passive Engagement", "Voting", "Campaigning", "Protesting", "Elected SG", "Leading Org."),
       caption.above = TRUE, digits = 3, stars = c(0.001, 0.01, 0.05),
       custom.coef.names = c("(Intercept)", 
                             "Lagged DV", 
                             "22-32 perc. affluent", 
                             "32-42 perc. affluent", 
                             "42-55 perc. affluent", 
                             "More than 55 perc. affluent", 
                             "High standardized test score",
                             "Missing test score",
                             "Female",
                             "Asian",
                             "Latino",
                             "Black",
                             "Other race",
                             "Jewish",
                             "Catholic",
                             "Evangelical",
                             "Other or no religion",
                             "English second language",
                             "Aged 17 or less",
                             "Aged 19",
                             "Aged 20",
                             "Social science major",
                             "Humanities major",
                             "Science major",
                             "Business major",
                             "Attend to make money",
                             "Proportion high standardized test score",
                             "Proportion Asian",
                             "Proportion Latino ",
                             "Proportion other race ",
                             "Proportion Jewish ",
                             "Proportion Catholic ",
                             "Proportion Evangelical",
                             "Proportion other or no religion",
                             "Proportion English second languages ",
                             "Proportion aged 17 or less",
                             "Proportion aged 19",
                             "Proportion aged 20",
                             "Proportion social science major",
                             "Proportion humanities major",
                             "Proportion science major",
                             "Proportion business major",
                             "Proportion attending to make money",
                             "Mostly female",
                             "Mostly Black",
                             "Large student body",
                             "Public", 
                             "College",
                             "Northeast",
                             "South",
                             "1995",
                             "1996",
                             "1997",
                             "1998",
                             "1999",
                             "2000",
                             "2001",
                             "2002",
                             "2003",
                             "2004",
                             "2005",
                             "2006",
                             "2007",
                             "2008",
                             "2009",
                             "2010",
                             "2011",
                             "2012",
                             "2013",
                             "Lagged DV",
                             "Lagged DV",
                             "Lagged DV",
                             "Lagged DV"))

texreg(list(passive.mis, voteprez2.mis, campaign.mis, protest.mis, elected.mis, orglead.mis),
       caption = "The Effect of Campus Affluence on Political Participation", 
       custom.model.names = c("Passive Engagement", "Voting", "Campaigning", "Protesting", "Elected SG", "Leading Org."),
       caption.above = TRUE, digits = 3, stars = c(0.001, 0.01, 0.05),
       custom.coef.names = c("(Intercept)", 
                             "Lagged DV", 
                             "22-32 perc. affluent", 
                             "32-42 perc. affluent", 
                             "42-55 perc. affluent", 
                             "More than 55 perc. affluent", 
                             "High standardized test score",
                             "Missing test score",
                             "Female",
                             "Asian",
                             "Latino",
                             "Black",
                             "Other race",
                             "Jewish",
                             "Catholic",
                             "Evangelical",
                             "Other or no religion",
                             "English second language",
                             "Aged 17 or less",
                             "Aged 19",
                             "Aged 20",
                             "Social science major",
                             "Humanities major",
                             "Science major",
                             "Business major",
                             "Attend to make money",
                             "Proportion high standardized test score",
                             "Proportion Asian",
                             "Proportion Latino ",
                             "Proportion other race ",
                             "Proportion Jewish ",
                             "Proportion Catholic ",
                             "Proportion Evangelical",
                             "Proportion other or no religion",
                             "Proportion English second languages ",
                             "Proportion aged 17 or less",
                             "Proportion aged 19",
                             "Proportion aged 20",
                             "Proportion social science major",
                             "Proportion humanities major",
                             "Proportion science major",
                             "Proportion business major",
                             "Proportion attending to make money",
                             "Mostly female",
                             "Mostly Black",
                             "Large student body",
                             "Public", 
                             "College",
                             "Northeast",
                             "South",
                             "1995",
                             "1996",
                             "1997",
                             "1998",
                             "1999",
                             "2000",
                             "2001",
                             "2002",
                             "2003",
                             "2004",
                             "2005",
                             "2006",
                             "2007",
                             "2008",
                             "2009",
                             "2010",
                             "2011",
                             "2012",
                             "2013",
                             "Lagged DV",
                             "Lagged DV",
                             "Lagged DV",
                             "Lagged DV"))

texreg(list(passive.his, voteprez2.his, campaign.his, protest.his, elected.his, orglead.his),
       caption = "The Effect of Campus Affluence on Political Participation", 
       custom.model.names = c("Passive Engagement", "Voting", "Campaigning", "Protesting", "Elected SG", "Leading Org."),
       caption.above = TRUE, digits = 3, stars = c(0.001, 0.01, 0.05),
       custom.coef.names = c("(Intercept)", 
                             "Lagged DV", 
                             "22-32 perc. affluent", 
                             "32-42 perc. affluent", 
                             "42-55 perc. affluent", 
                             "More than 55 perc. affluent", 
                             "High standardized test score",
                             "Missing test score",
                             "Female",
                             "Asian",
                             "Latino",
                             "Black",
                             "Other race",
                             "Jewish",
                             "Catholic",
                             "Evangelical",
                             "Other or no religion",
                             "English second language",
                             "Aged 17 or less",
                             "Aged 19",
                             "Aged 20",
                             "Social science major",
                             "Humanities major",
                             "Science major",
                             "Business major",
                             "Attend to make money",
                             "Proportion high standardized test score",
                             "Proportion Asian",
                             "Proportion Latino ",
                             "Proportion other race ",
                             "Proportion Jewish ",
                             "Proportion Catholic ",
                             "Proportion Evangelical",
                             "Proportion other or no religion",
                             "Proportion English second languages ",
                             "Proportion aged 17 or less",
                             "Proportion aged 19",
                             "Proportion aged 20",
                             "Proportion social science major",
                             "Proportion humanities major",
                             "Proportion science major",
                             "Proportion business major",
                             "Proportion attending to make money",
                             "Mostly female",
                             "Mostly Black",
                             "Large student body",
                             "Public", 
                             "College",
                             "Northeast",
                             "South",
                             "1995",
                             "1996",
                             "1997",
                             "1998",
                             "1999",
                             "2000",
                             "2001",
                             "2002",
                             "2003",
                             "2004",
                             "2005",
                             "2006",
                             "2007",
                             "2008",
                             "2009",
                             "2010",
                             "2011",
                             "2012",
                             "2013",
                             "Lagged DV",
                             "Lagged DV",
                             "Lagged DV",
                             "Lagged DV"))

####################
# Appendix Table 8 #
####################

texreg(list(passive.lis.close, voteprez2.lis.close, campaign.lis.close, protest.lis.close, elected.lis.close, orglead.lis.close),
       caption = "The Effect of Campus Affluence on Students that wanted to live near home", 
       custom.model.names = c("Passive Engagement", "Voting", "Campaigning", "Protesting", "Elected S.G.", "Leading Org."),
       caption.above = TRUE, digits = 3, stars = c(0.001, 0.01, 0.05))

texreg(list(passive.lis.sports, voteprez2.lis.sports, elected.lis.sports, orglead.lis.sports),
       caption = "The Effect of Campus Affluence on Students that were recruited for athletics", 
       custom.model.names = c("Passive Engagement", "Voting", "Elected S.G.", "Leading Org."),
       caption.above = TRUE, digits = 3, stars = c(0.001, 0.01, 0.05))

texreg(list(passive.lis.choice, voteprez2.lis.choice, orglead.lis.choice),
       caption = "The Effect of Campus Affluence on Students that could not afford first-choice", 
       custom.model.names = c("Passive Engagement", "Voting","Leading Org."),
       caption.above = TRUE, digits = 3, stars = c(0.001, 0.01, 0.05))

####################
# Appendix Table 9 #
####################

#low importance
texreg(list(passive.lis.polsub1.pa, voteprez2.lis.polsub1.pa, campaign.lis.polsub1.pa, protest.lis.polsub1.pa, elected.lis.polsub1.pa),
       caption = "The Effect of Campus Affluence on Political Participation for LIS subsets", 
       caption.above = TRUE, digits = 3, stars = c(0.001, 0.01, 0.05),
       custom.model.names = c("Passive Engagement", "Voting", "Campaigning", "Protesting", "Elected SG"))

#medium importance
texreg(list(passive.lis.polsub2.pa, voteprez2.lis.polsub2.pa, campaign.lis.polsub2.pa, protest.lis.polsub2.pa, elected.lis.polsub2.pa),
       caption = "The Effect of Campus Affluence on Political Participation for LIS subsets", 
       caption.above = TRUE, digits = 3, stars = c(0.001, 0.01, 0.05),
       custom.model.names = c("Passive Engagement", "Voting", "Campaigning", "Protesting", "Elected SG"))

#high importance
texreg(list(passive.lis.polsub3.pa, voteprez2.lis.polsub3.pa, campaign.lis.polsub3.pa, protest.lis.polsub3.pa, elected.lis.polsub3.pa),
       caption = "The Effect of Campus Affluence on Political Participation for LIS subsets", 
       caption.above = TRUE, digits = 3, stars = c(0.001, 0.01, 0.05),
       custom.model.names = c("Passive Engagement", "Voting", "Campaigning", "Protesting", "Elected SG"))


####################
# Appendix Table 10 #
####################

######################################
## Political Norm Mediation Analysis #
######################################

# Passive

passive.lisB <- lmer(passive_index_css_avg ~ passive_tfs_cohort + passive_index_tfs_avg + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                       evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                       hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                       age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                       largesb + public + college + neast + south + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), data = data.lis[!is.na(data.lis$passive_tfs_cohort),])  
#summary(passive.lisB)

# Voting

voteprez2.lisB <- glmer(voteprez2 ~ passive_tfs_cohort + polaffairs_tfs + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                          otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                          hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                          socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                          factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis[!is.na(data.lis$passive_tfs_cohort),])
#summary(voteprez2.lisB)

# Campaign


campaign.lisB <- glmer(campaign_css ~ passive_tfs_cohort + campaign_tfs + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                         otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                         hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                         socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                         factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis[!is.na(data.lis$passive_tfs_cohort),])
#summary(campaign.lisB)

# Student government


elected.lisB <- glmer(elected01_gov ~ passive_tfs_cohort + commlead_tfs + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                        otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                        hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                        socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                        factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis[!is.na(data.lis$passive_tfs_cohort),])
#summary(elected.lisB)

# Organizational leader

orglead.lisB <- glmer(orglead01 ~ passive_tfs_cohort + commlead_tfs + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                        otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                        hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                        socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                        factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis[!is.na(data.lis$passive_tfs_cohort),])
#summary(orglead.lisB) 

# Protest

protest.lisB <-  glmer(protestindex_css ~ passive_tfs_cohort + protest_tfs + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                         otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                         hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                         socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                         factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis[!is.na(data.lis$passive_tfs_cohort),])
#summary(protest.lisB)


texreg(list(passive.lisB, voteprez2.lisB, campaign.lisB, protest.lisB, elected.lisB, orglead.lisB),
       caption = "The Effect of Campus Affluence on Political Participation", 
       custom.model.names = c("Passive Engagement", "Voting", "Campaigning", "Protesting", "Elected SG", "Leading Org."),
       caption.above = TRUE, digits = 3, stars = c(0.001, 0.01, 0.05),
       custom.coef.names = c("(Intercept)", 
                             "Cohort Political Norm (TFS)",
                             "Lagged DV", 
                             "22-32 perc. affluent", 
                             "32-42 perc. affluent", 
                             "42-55 perc. affluent", 
                             "More than 55 perc. affluent", 
                             "High standardized test score",
                             "Missing test score",
                             "Female",
                             "Asian",
                             "Latino",
                             "Black",
                             "Other race",
                             "Jewish",
                             "Catholic",
                             "Evangelical",
                             "Other or no religion",
                             "English second language",
                             "Aged 17 or less",
                             "Aged 19",
                             "Aged 20",
                             "Social science major",
                             "Humanities major",
                             "Science major",
                             "Business major",
                             "Attend to make money",
                             "Proportion high standardized test score",
                             "Proportion Asian",
                             "Proportion Latino ",
                             "Proportion other race ",
                             "Proportion Jewish ",
                             "Proportion Catholic ",
                             "Proportion Evangelical",
                             "Proportion other or no religion",
                             "Proportion English second languages ",
                             "Proportion aged 17 or less",
                             "Proportion aged 19",
                             "Proportion aged 20",
                             "Proportion social science major",
                             "Proportion humanities major",
                             "Proportion science major",
                             "Proportion business major",
                             "Proportion attending to make money",
                             "Mostly female",
                             "Mostly Black",
                             "Large student body",
                             "Public", 
                             "College",
                             "Northeast",
                             "South",
                             "1995",
                             "1996",
                             "1997",
                             "1998",
                             "1999",
                             "2000",
                             "2001",
                             "2002",
                             "2003",
                             "2004",
                             "2005",
                             "2006",
                             "2007",
                             "2008",
                             "2009",
                             "2010",
                             "2011",
                             "2012",
                             "2013",
                             "Lagged DV", 
                             "Lagged DV",
                             "Lagged DV",  
                             "Lagged DV"))

####################################
## Turnout Rate Mediation Analysis #
####################################

# Load data for turnout analysis

lis.turn <- read.dta("turnout.dta")

# Passive

passive.lisB <- lmer(passive_index_css_avg ~ voteprez2_cohort + passive_index_tfs_avg + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                      evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                      hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                      age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                      largesb + public + college + neast + south + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), data = lis.turn[!is.na(lis.turn$voteprez2_cohort),])  
#summary(passive.lisB)

# Voting

voteprez2.lisB <- glmer(voteprez2 ~ voteprez2_cohort + polaffairs_tfs + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                        otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                        hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                        socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                        factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = lis.turn[!is.na(lis.turn$voteprez2_cohort),])
#summary(voteprez2.lisB)

# Campaign

campaign.lisB <- glmer(campaign_css ~ voteprez2_cohort + campaign_tfs + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                        otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                        hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                        socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                        factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = lis.turn[!is.na(lis.turn$voteprez2_cohort),])
#summary(campaign.lisB)

# Student government

elected.lisB <- glmer(elected01_gov ~ voteprez2_cohort + commlead_tfs + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                       otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                       hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                       socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                       factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = lis.turn[!is.na(lis.turn$voteprez2_cohort),])
#summary(elected.lisB)

# Organizational leader

orglead.lisB <- glmer(orglead01 ~ voteprez2_cohort + commlead_tfs + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                       otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                       hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                       socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                       factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = lis.turn[!is.na(lis.turn$voteprez2_cohort),])
#summary(orglead.lisB) 

# Protest

protest.lisB <-  glmer(protestindex_css ~ voteprez2_cohort + protest_tfs + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                        otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                        hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                        socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                        factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = lis.turn[!is.na(lis.turn$voteprez2_cohort),])
#summary(protest.lisB)

texreg(list(passive.lisB, voteprez2.lisB, campaign.lisB, protest.lisB, elected.lisB, orglead.lisB),
       caption = "The Effect of Campus Affluence on Political Participation", 
       custom.model.names = c("Passive Engagement", "Voting", "Campaigning", "Protesting", "Elected SG", "Leading Org."),
       caption.above = TRUE, digits = 3, stars = c(0.001, 0.01, 0.05),
              custom.coef.names = c("(Intercept)", 
                             "Cohort Turnout Rate",
                             "Lagged DV", 
                             "23-33 perc. affluent", 
                             "33-43 perc. affluent", 
                             "43-57 perc. affluent", 
                             "More than 57 perc. affluent", 
                             "High standardized test score",
                             "Missing test score",
                             "Female",
                             "Asian",
                             "Latino",
                             "Black",
                             "Other race",
                             "Jewish",
                             "Catholic",
                             "Evangelical",
                             "Other or no religion",
                             "English second language",
                             "Aged 17 or less",
                             "Aged 19",
                             "Aged 20",
                             "Social science major",
                             "Humanities major",
                             "Science major",
                             "Business major",
                             "Attend to make money",
                             "Proportion high standardized test score",
                             "Proportion Asian",
                             "Proportion Latino ",
                             "Proportion other race ",
                             "Proportion Jewish ",
                             "Proportion Catholic ",
                             "Proportion Evangelical",
                             "Proportion other or no religion",
                             "Proportion English second languages ",
                             "Proportion aged 17 or less",
                             "Proportion aged 19",
                             "Proportion aged 20",
                             "Proportion social science major",
                             "Proportion humanities major",
                             "Proportion science major",
                             "Proportion business major",
                             "Proportion attending to make money",
                             "Mostly female",
                             "Mostly Black",
                             "Large student body",
                             "Public", 
                             "College",
                             "Northeast",
                             "South",
                             "1995",
                             "1996",
                             "1997",
                             "1998",
                             "1999",
                             "2000",
                             "2001",
                             "2002",
                             "2003",
                             "2004",
                             "2005",
                             "2006",
                             "2007",
                             "2008",
                             "2009",
                             "2010",
                             "2011",
                             "2012",
                             "2013",
                             "Lagged DV", 
                             "Lagged DV",
                             "Lagged DV",  
                             "Lagged DV"))

#####################
# Appendix Table 11 #
#####################

#############################################################
## IV: Tables for Appendix
#############################################################

## Create a contunous numerical version of "distance from home"
csscohort$distancehome <- as.numeric(csscohort$DISTHOME_TFS)
describe(csscohort$distancehome)
sd(csscohort$distancehome, na.rm = T)
data.lis$distancehome <- as.numeric(data.lis$DISTHOME_TFS)
table(data.lis$distancehome)
describe(data.lis$distancehome)
sd(data.lis$distancehome, na.rm = T)

## Instrument, distance to school from permanent home
data.lis$distanceclose <- ifelse(data.lis$distancehome <= 3, 1, 0) ## Less than 100 
table(data.lis$distanceclose)
describe(data.lis$distanceclose)
sd(data.lis$distanceclose, na.rm = T)

csscohort$distanceclose <- ifelse(csscohort$distancehome <= 3, 1, 0) ## Less than 100 
describe(csscohort$distanceclose)
sd(csscohort$distanceclose, na.rm = T)

data.lis$distancecloser <- ifelse(data.lis$distancehome <= 2, 1, 0) ## Less than 50    
table(data.lis$distancecloser)
describe(data.lis$distancecloser)
sd(data.lis$distancecloser, na.rm = T)

csscohort$distancecloser <- ifelse(csscohort$distancehome <= 2, 1, 0) ## Less than 100 
describe(csscohort$distancecloser)
sd(csscohort$distancecloser, na.rm = T)


## Check correlation between distance from home and affluence
cor(data.lis$distancehome, data.lis$affcat, use="complete.obs", method="kendall") 
## 0.1578

## create a treatment 1 = attends most affluent schools 0 = does not
data.lis$treat <- ifelse(data.lis$affcat == 5, 1, 0)
table(data.lis$treat)

csscohort$treat <- ifelse(csscohort$affcat == 5, 1, 0)
table(csscohort$treat)

cor(data.lis$distancehome, data.lis$treat, use="complete.obs", method="kendall") 
##0.1717

#############################################################
## Check correlations
#############################################################

## Check correlations between distance from home and affluence categories
a <- cor(data.lis$distancehome, data.lis$affcat, use="complete.obs") 
a
## 0.19
b <- cor(data.lis$distanceclose, data.lis$affcat, use="complete.obs") 
b
## -0.18
c<- cor(data.lis$distancecloser, data.lis$affcat, use="complete.obs") 
## -0.1485
c
## Check correlations between distance from home and affluence treatment
d <- cor(data.lis$distancehome, data.lis$treat, use="complete.obs") 
d
## 0.19
e <- cor(data.lis$distanceclose, data.lis$treat, use="complete.obs") 
e
## -0.17
f <- cor(data.lis$distancecloser, data.lis$treat, use="complete.obs") 
f
## -0.13

#now for entire sample

## Check correlations between distance from home and affluence categories
a1 <- cor(csscohort$distancehome, csscohort$affcat, use="complete.obs") 
## 0.26
a1
b1 <- cor(csscohort$distanceclose, csscohort$affcat, use="complete.obs") 
b1
## -0.23
c1 <- cor(csscohort$distancecloser, csscohort$affcat, use="complete.obs") 
c1
## -0.20

## Check correlations between distance from home and affluence treatment
d1 <- cor(csscohort$distancehome, csscohort$treat, use="complete.obs") 
d1
## 0.24
e1 <- cor(csscohort$distanceclose, csscohort$treat, use="complete.obs") 
e1
## -0.21
f1 <- cor(csscohort$distancecloser, csscohort$treat, use="complete.obs") 
f1
## -0.19

## IV diagnostics tables
table <- matrix(c(a,b,c,a1,b1,c1,d,e,f,d1,e1,f1),ncol=3,byrow=TRUE)
xtable(table)

#############################################################
## 1st stage diagnostics
#############################################################
fit1 <- lm(treat~ distancehome, data = data.lis)
summary(fit1)

## adjusted R2 = 0.036
## distance home coef = 0.056 t = 24.942

fit1a <- lm(treat~ distanceclose, data = data.lis)
summary(fit1a)

## adjusted R2 = 0.029
## distance home coef = -0.137 t = -22.69

fit1b <- lm(treat~ distancecloser, data = data.lis)
summary(fit1b)
## adjusted R2 = 0.018
## distance home coef = -0.113 t = -17.95

texreg(list(fit1, fit1a, fit1b),
       caption = "Stage 1: IV Analysis, Affluenece Treatment onto Distance from home", 
       caption.above = TRUE, digits = 3, stars = c(0.001, 0.01, 0.05),
       custom.model.names = c("Continuous Distance", "Less than 100 miles", "Less than 50 miles"),
       naive=T)

## run 1st stage with full controls?

fit2a <- lm(treat ~ distancehome + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
              evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
              hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
              age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
              largesb + public + college + neast + south + as.factor(YEAR), data = data.lis)  
summary(fit2a)
## adjusted R2 = 0.557
## distance home coef = 0.012 t = 6.279

fit2b <- lm(treat ~ distanceclose + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
              evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
              hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
              age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
              largesb + public + college + neast + south + as.factor(YEAR), data = data.lis) 
summary(fit2b)
## adjusted R2 = 0.557
## distance home coef = -0.027 t = -5.331

fit2c <- lm(treat ~ distancecloser + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
              evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
              hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
              age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
              largesb + public + college + neast + south + as.factor(YEAR), data = data.lis) 
summary(fit2c)
## adjusted R2 = 0.556
## distance home coef = -0.024 t = -4.672

texreg(list(fit2a, fit2b, fit2c),
       caption = "Stage 1: IV Analysis", 
       caption.above = TRUE, digits = 3, stars = c(0.001, 0.01, 0.05),
       custom.model.names = c("Continuous Distance", "Less than 100 miles", "Less than 50 miles"),
       naive=T)

#############################################################
## Passive participation
#############################################################
library(AER)

iv2b <- ivreg(passive_index_css_avg ~ treat + passive_index_tfs_avg + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                largesb + public + college + neast + south + as.factor(YEAR) | 
                distancehome + passive_index_tfs_avg +  hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                largesb + public + college + neast + south + as.factor(YEAR), data =data.lis)                                     
summary(iv2b, test = "F")                                    

iv3b <- ivreg(passive_index_css_avg ~ treat + passive_index_tfs_avg + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                largesb + public + college + neast + south + as.factor(YEAR) | 
                distanceclose + passive_index_tfs_avg +  hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                largesb + public + college + neast + south + as.factor(YEAR), data =data.lis)                                     
summary(iv3b, test = "F")                                    

iv4b <- ivreg(passive_index_css_avg ~ treat + passive_index_tfs_avg + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                largesb + public + college + neast + south + as.factor(YEAR) | 
                distancecloser + passive_index_tfs_avg +  hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                largesb + public + college + neast + south + as.factor(YEAR), data =data.lis)                                     

summary(iv4b, test = "F")                                    

texreg(list(iv2b, iv3b, iv4b),
       caption = "Passive Participation: IV Analysis, Distance to School as Instrument", 
       caption.above = TRUE, digits = 3, stars = c(0.001, 0.01, 0.05),
       custom.model.names = c("Continuous Distance", "Less than 100 miles", "Less than 50 miles"),
       naive=T,
       custom.coef.names = c("Intercept",  "Attending affluent school", "Lagged DV", 
                             "High standardized test score","Missing test score","Female","Asian", "Latino","Black","Other race","Jewish","Catholic","Evangelical","Other or no religion",
                             "English second language","Aged 17 or less","Aged 19","Aged 20", "Social science major","Humanities major","Science major","Business major","Attend to make money",
                             "Proportion high standardized test score","Proportion Asian","Proportion Latino ","Proportion other race ","Proportion Jewish ","Proportion Catholic ",
                             "Proportion Evangelical","Proportion other or no religion","Proportion English second languages ", "Proportion aged 17 or less","Proportion aged 19",
                             "Proportion aged 20","Proportion social science major","Proportion humanities major","Proportion science major","Proportion business major",
                             "Proportion attending to make money","Mostly female","Mostly Black","Large student body","Public", "College","Northeast","South","1995","1996","1997",
                             "1998","1999","2000","2001","2002","2003","2004","2005","2006","2007", "2008","2009","2010", "2011","2012","2013"))

#############################################################
## voting
#############################################################

iv2c <- ivreg(voteprez2 ~ treat + polaffairs_tfs + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                largesb + public + college + neast + south + as.factor(YEAR) | 
                distancehome + polaffairs_tfs +  hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                largesb + public + college + neast + south + as.factor(YEAR), data =data.lis)                                     
summary(iv2c, test = "F")                                    

iv3c <- ivreg(voteprez2 ~ treat + polaffairs_tfs + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                largesb + public + college + neast + south + as.factor(YEAR) | 
                distanceclose + polaffairs_tfs +  hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                largesb + public + college + neast + south + as.factor(YEAR), data =data.lis)                                     
summary(iv3c, test = "F")                                    

iv4c <- ivreg(voteprez2 ~ treat + polaffairs_tfs + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                largesb + public + college + neast + south + as.factor(YEAR) | 
                distancecloser + polaffairs_tfs +  hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                largesb + public + college + neast + south + as.factor(YEAR), data =data.lis)                                     
summary(iv4c, test = "F")   

texreg(list(iv2c, iv3c, iv4c),
       caption = "Voting: IV Analysis, Distance to School as Instrument", 
       caption.above = TRUE, digits = 3, stars = c(0.001, 0.01, 0.05),
       custom.model.names = c("Continuous Distance", "Less than 100 miles", "Less than 50 miles"),
       naive=T,
       custom.coef.names = c("Intercept",  "Attending affluent school", "Lagged DV", 
                             "High standardized test score","Missing test score","Female","Asian", "Latino","Black","Other race","Jewish","Catholic","Evangelical","Other or no religion",
                             "English second language","Aged 17 or less","Aged 19","Aged 20", "Social science major","Humanities major","Science major","Business major","Attend to make money",
                             "Proportion high standardized test score","Proportion Asian","Proportion Latino ","Proportion other race ","Proportion Jewish ","Proportion Catholic ",
                             "Proportion Evangelical","Proportion other or no religion","Proportion English second languages ", "Proportion aged 17 or less","Proportion aged 19",
                             "Proportion aged 20","Proportion social science major","Proportion humanities major","Proportion science major","Proportion business major",
                             "Proportion attending to make money","Mostly female","Mostly Black","Large student body","Public", "College","Northeast","South","1996","1997",
                             "1998","2001","2005","2006","2007", "2009", "2013"))

#############################################################
## Campaigning
#############################################################

iv2d <- ivreg(campaign_css ~ treat + campaign_tfs + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                largesb + public + college + neast + south + as.factor(YEAR) | 
                distancehome + campaign_tfs +  hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                largesb + public + college + neast + south + as.factor(YEAR), data =data.lis)                                     
summary(iv2d, test = "F")                                    

iv3d <- ivreg(campaign_css ~ treat + campaign_tfs + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                largesb + public + college + neast + south + as.factor(YEAR) | 
                distanceclose + campaign_tfs +  hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                largesb + public + college + neast + south + as.factor(YEAR), data =data.lis)                                     
summary(iv3d, test = "F")                                    

iv4d <- ivreg(campaign_css ~ treat + campaign_tfs + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                largesb + public + college + neast + south + as.factor(YEAR) | 
                distancecloser + campaign_tfs +  hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                largesb + public + college + neast + south + as.factor(YEAR), data =data.lis)                                     
summary(iv4d, test = "F")  


texreg(list(iv2d, iv3d, iv4d),
       caption = "Campaigning: IV Analysis, Distance to School as Instrument", 
       caption.above = TRUE, digits = 3, stars = c(0.001, 0.01, 0.05),
       custom.model.names = c("Continuous Distance", "Less than 100 miles", "Less than 50 miles"),
       naive=T,
       custom.coef.names = c("Intercept",  "Attending affluent school", "Lagged DV", 
                             "High standardized test score","Missing test score","Female","Asian", "Latino","Black","Other race","Jewish","Catholic","Evangelical","Other or no religion",
                             "English second language","Aged 17 or less","Aged 19","Aged 20", "Social science major","Humanities major","Science major","Business major","Attend to make money",
                             "Proportion high standardized test score","Proportion Asian","Proportion Latino ","Proportion other race ","Proportion Jewish ","Proportion Catholic ",
                             "Proportion Evangelical","Proportion other or no religion","Proportion English second languages ", "Proportion aged 17 or less","Proportion aged 19",
                             "Proportion aged 20","Proportion social science major","Proportion humanities major","Proportion science major","Proportion business major",
                             "Proportion attending to make money","Mostly female","Mostly Black","Large student body","Public", "College","Northeast","South","1997",
                             "1998","1999", "2001","2008","2009","2010","2011"))

#############################################################
## Elected to student office
#############################################################

iv2e <- ivreg(elected01_gov ~ treat + commlead_tfs + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                largesb + public + college + neast + south + as.factor(YEAR) | 
                distancehome + commlead_tfs +  hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                largesb + public + college + neast + south + as.factor(YEAR), data =data.lis)                                     
summary(iv2e, test = "F")                                    

iv3e <- ivreg(elected01_gov ~ treat + commlead_tfs + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                largesb + public + college + neast + south + as.factor(YEAR) | 
                distanceclose + commlead_tfs +  hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                largesb + public + college + neast + south + as.factor(YEAR), data =data.lis)                                     
summary(iv3e, test = "F")                                    

iv4e <- ivreg(elected01_gov ~ treat + commlead_tfs + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                largesb + public + college + neast + south + as.factor(YEAR) | 
                distancecloser + commlead_tfs +  hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                largesb + public + college + neast + south + as.factor(YEAR), data =data.lis)                                     
summary(iv4e, test = "F")  

texreg(list(iv2e, iv3e, iv4e),
       caption = "Elected to Student Office: IV Analysis, Distance to School as Instrument", 
       caption.above = TRUE, digits = 3, stars = c(0.001, 0.01, 0.05),
       custom.model.names = c("Continuous Distance", "Less than 100 miles", "Less than 50 miles"),
       naive=T,
       custom.coef.names = c("Intercept",  "Attending affluent school", "Lagged DV", 
                             "High standardized test score","Missing test score","Female","Asian", "Latino","Black","Other race","Jewish","Catholic","Evangelical","Other or no religion",
                             "English second language","Aged 17 or less","Aged 19","Aged 20", "Social science major","Humanities major","Science major","Business major","Attend to make money",
                             "Proportion high standardized test score","Proportion Asian","Proportion Latino ","Proportion other race ","Proportion Jewish ","Proportion Catholic ",
                             "Proportion Evangelical","Proportion other or no religion","Proportion English second languages ", "Proportion aged 17 or less","Proportion aged 19",
                             "Proportion aged 20","Proportion social science major","Proportion humanities major","Proportion science major","Proportion business major",
                             "Proportion attending to make money","Mostly female","Mostly Black","Large student body","Public", "College","Northeast","South","1996", "1997",
                             "1998","1999", "2000", "2001","2002","2003","2004","2005", "2006"))

#############################################################
## Leader of a student organization
#############################################################
iv2f <- ivreg(orglead01 ~ treat + commlead_tfs + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                largesb + public + college + neast + south + as.factor(YEAR) | 
                distancehome + commlead_tfs +  hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                largesb + public + college + neast + south + as.factor(YEAR), data =data.lis)                                     
summary(iv2f, test = "F")                                    

iv3f <- ivreg(orglead01 ~ treat + commlead_tfs + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                largesb + public + college + neast + south + as.factor(YEAR) | 
                distanceclose + commlead_tfs +  hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                largesb + public + college + neast + south + as.factor(YEAR), data =data.lis)                                     
summary(iv3f, test = "F")                                    

iv4f <- ivreg(orglead01 ~ treat + commlead_tfs + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                largesb + public + college + neast + south + as.factor(YEAR) | 
                distancecloser + commlead_tfs +  hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                largesb + public + college + neast + south + as.factor(YEAR), data =data.lis)                                     
summary(iv4f, test = "F")  

texreg(list(iv2f, iv3f, iv4f),
       caption = "Lead a Student Organization: IV Analysis, Distance to School as Instrument", 
       caption.above = TRUE, digits = 3, stars = c(0.001, 0.01, 0.05),
       custom.model.names = c("Continuous Distance", "Less than 100 miles", "Less than 50 miles"),
       naive=T,
       custom.coef.names = c("Intercept",  "Attending affluent school", "Lagged DV", 
                             "High standardized test score","Missing test score","Female","Asian", "Latino","Black","Other race","Jewish","Catholic","Evangelical","Other or no religion",
                             "English second language","Aged 17 or less","Aged 19","Aged 20", "Social science major","Humanities major","Science major","Business major","Attend to make money",
                             "Proportion high standardized test score","Proportion Asian","Proportion Latino ","Proportion other race ","Proportion Jewish ","Proportion Catholic ",
                             "Proportion Evangelical","Proportion other or no religion","Proportion English second languages ", "Proportion aged 17 or less","Proportion aged 19",
                             "Proportion aged 20","Proportion social science major","Proportion humanities major","Proportion science major","Proportion business major",
                             "Proportion attending to make money","Mostly female","Mostly Black","Large student body","Public", "College","Northeast","South","2011", "2012","2013"))

#############################################################
## Protest index
#############################################################
iv2g <- ivreg(protestindex_css ~ treat + protest_tfs + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                largesb + public + college + neast + south + as.factor(YEAR) | 
                distancehome + protest_tfs +  hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                largesb + public + college + neast + south + as.factor(YEAR), data =data.lis)                                     
summary(iv2g, test = "F")                                    

iv3g <- ivreg(protestindex_css ~ treat + protest_tfs + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                largesb + public + college + neast + south + as.factor(YEAR) | 
                distanceclose + protest_tfs +  hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                largesb + public + college + neast + south + as.factor(YEAR), data =data.lis)                                     
summary(iv3g, test = "F")                                    

iv4g <- ivreg(protestindex_css ~ treat + protest_tfs + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                largesb + public + college + neast + south + as.factor(YEAR) | 
                distancecloser + protest_tfs +  hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                largesb + public + college + neast + south + as.factor(YEAR), data =data.lis)                                     
summary(iv4g, test = "F")  

texreg(list(iv2g, iv3g, iv4g),
       caption = "Participate in Protest: IV Analysis, Distance to School as Instrument", 
       caption.above = TRUE, digits = 3, stars = c(0.001, 0.01, 0.05),
       custom.model.names = c("Continuous Distance", "Less than 100 miles", "Less than 50 miles"),
       naive=T,
       custom.coef.names = c("Intercept",  "Attending affluent school", "Lagged DV", 
                             "High standardized test score","Missing test score","Female","Asian", "Latino","Black","Other race","Jewish","Catholic","Evangelical","Other or no religion",
                             "English second language","Aged 17 or less","Aged 19","Aged 20", "Social science major","Humanities major","Science major","Business major","Attend to make money",
                             "Proportion high standardized test score","Proportion Asian","Proportion Latino ","Proportion other race ","Proportion Jewish ","Proportion Catholic ",
                             "Proportion Evangelical","Proportion other or no religion","Proportion English second languages ", "Proportion aged 17 or less","Proportion aged 19",
                             "Proportion aged 20","Proportion social science major","Proportion humanities major","Proportion science major","Proportion business major",
                             "Proportion attending to make money","Mostly female","Mostly Black","Large student body","Public", "College","Northeast","South","1995","1996","1997","1998",
                             "1999","2000","2001","2002","2003","2004", "2005","2006","2007","2008","2009"))

#####################
# Appendix Table 12 #
#####################

texreg(list(academcomp.lis, motivationlead.lis, hpwworking.lis, emohealth.lis, socsatis.lis, soccon.lis ),
       custom.model.names = c("Academic Competence", "Motivation to Lead", "Working Less", "Emotional Health", "Social Satisfaction", "Social Confidence"),
       caption.above = TRUE, digits = 3, stars = c(0.001, 0.01, 0.05))

texreg(list(academcomp.mis, motivationlead.mis, hpwworking.mis, emohealth.mis, socsatis.mis, soccon.mis ),
       custom.model.names = c("Academic Competence", "Motivation to Lead", "Working Less", "Emotional Health", "Social Satisfaction", "Social Confidence"),
       caption.above = TRUE, digits = 3, stars = c(0.001, 0.01, 0.05))

texreg(list(academcomp.his, motivationlead.his, hpwworking.his, emohealth.his, socsatis.his, soccon.his ),
       custom.model.names = c("Academic Competence", "Motivation to Lead", "Working Less", "Emotional Health", "Social Satisfaction", "Social Confidence"),
       caption.above = TRUE, digits = 3, stars = c(0.001, 0.01, 0.05))

#####################
# Appendix Table 13 #
#####################

texreg(list(passive.tfs.agg, collegeaidratio.agg ),
       custom.model.names = c("TFS Cohort Passive Engagement", "TFS Cohort Aid Ratio"),
       caption.above = TRUE, digits = 3, stars = c(0.001, 0.01, 0.05))
#####################
# Appendix Table 14 #
#####################


socmarg.lis <- lmer(socmarg_css ~ socmarg_tfs + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                      evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                      hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                      age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                      largesb + public + college + neast + south + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), data = data.lis)

socmarg.mis <- lmer(socmarg_css ~ socmarg_tfs + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                      evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                      hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                      age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                      largesb + public + college + neast + south + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), data = data.mis)

socmarg.his <- lmer(socmarg_css ~ socmarg_tfs + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                      evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                      hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                      age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                      largesb + public + college + neast + south + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), data = data.his)


workmerged.lis <- lmer(work_merged_full ~  factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                         evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                         hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                         age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                         largesb + public + college + neast + south + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), data = data.lis)

workmerged.mis <- lmer(work_merged_full ~  factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                         evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                         hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                         age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                         largesb + public + college + neast + south + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), data = data.mis)

workmerged.his <- lmer(work_merged_full ~  factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                         evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                         hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                         age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                         largesb + public + college + neast + south + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), data = data.his)


emodifficulty.lis <- lmer(emodifficulty_css ~ emohealth_tfs + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                            evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                            hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                            age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                            largesb + public + college + neast + south + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), data = data.lis)

emodifficulty.mis <- lmer(emodifficulty_css ~ emohealth_tfs + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                            evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                            hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                            age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                            largesb + public + college + neast + south + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), data = data.mis)

emodifficulty.his <- lmer(emodifficulty_css ~ emohealth_tfs + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                            evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                            hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                            age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                            largesb + public + college + neast + south + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), data = data.his)


academcomp2.lis <- lmer(academcomp2_css ~ hihsgpa + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                          evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                          hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                          age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                          largesb + public + college + neast + south + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), data = data.lis)

academcomp2.mis <- lmer(academcomp2_css ~ hihsgpa + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                          evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                          hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                          age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                          largesb + public + college + neast + south + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), data = data.mis)

academcomp2.his <- lmer(academcomp2_css ~ hihsgpa + factor(affcat) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                          evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                          hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                          age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                          largesb + public + college + neast + south + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), data = data.his)

texreg(list(academcomp2.lis, workmerged.lis, emodifficulty.lis, socmarg.lis ),
       custom.model.names = c("Academic Competence (Self-Rated Changes)", "Working Less for Pay", "Psychological Health", "Social Well-Being"),
       caption.above = TRUE, digits = 3, stars = c(0.001, 0.01, 0.05))

texreg(list(academcomp2.mis, workmerged.mis, emodifficulty.mis, socmarg.mis ),
       custom.model.names = c("Academic Competence (Self-Rated Changes)", "Working Less for Pay", "Psychological Health", "Social Well-Being"),
       caption.above = TRUE, digits = 3, stars = c(0.001, 0.01, 0.05))

texreg(list(academcomp2.his, workmerged.his, emodifficulty.his , socmarg.his),
       custom.model.names = c("Academic Competence (Self-Rated Changes)", "Working Less for Pay", "Psychological Health", "Social Well-Being"),
       caption.above = TRUE, digits = 3, stars = c(0.001, 0.01, 0.05))

#####################
# Appendix Table 15 #
#####################

texreg(list(passive.lis.emohealth_tfs01, voteprez2.lis.emohealth_tfs01, campaign.lis.emohealth_tfs01, protest.lis.emohealth_tfs01, elected.lis.emohealth_tfs01, orglead.lis.emohealth_tfs01 ),
       caption = "The Effect of Campus Affluence on Emotional Health (Individual)", 
       custom.model.names = c("Passive Engagement", "Voting", "Campaigning", "Protesting", "Elected S.G.", "Leading Org."),
       caption.above = TRUE, digits = 3, stars = c(0.001, 0.01, 0.05),
       custom.coef.names = c("Intercept", 
                             "Lagged DV", 
                             "22-32 perc. affluent", 
                             "32-42 perc. affluent", 
                             "42-55 perc. affluent", 
                             "More than 55 perc. affluent", 
                             "moderator",
                             "High standardized test score",
                             "Missing test score",
                             "Female",
                             "Asian",
                             "Latino",
                             "Black",
                             "Other race",
                             "Jewish",
                             "Catholic",
                             "Evangelical",
                             "Other or no religion",
                             "English second language",
                             "Aged 17 or less",
                             "Aged 19",
                             "Aged 20",
                             "Social science major",
                             "Humanities major",
                             "Science major",
                             "Business major",
                             "Attend to make money",
                             "Proportion high standardized test score",
                             "Proportion Asian",
                             "Proportion Latino ",
                             "Proportion other race ",
                             "Proportion Jewish ",
                             "Proportion Catholic ",
                             "Proportion Evangelical",
                             "Proportion other or no religion",
                             "Proportion English second languages ",
                             "Proportion aged 17 or less",
                             "Proportion aged 19",
                             "Proportion aged 20",
                             "Proportion social science major",
                             "Proportion humanities major",
                             "Proportion science major",
                             "Proportion business major",
                             "Proportion attending to make money",
                             "Mostly female",
                             "Mostly Black",
                             "Large student body",
                             "Public", 
                             "College",
                             "Northeast",
                             "South",
                             "1995",
                             "1996",
                             "1997",
                             "1998",
                             "1999",
                             "2000",
                             "2001",
                             "2002",
                             "2003",
                             "2004",
                             "2005",
                             "2006",
                             "2007",
                             "2008",
                             "2009",
                             "2010",
                             "2011",
                             "2012",
                             "2013",
                             "22-32 perc. affluent X moderator", 
                             "32-42 perc. affluent X moderator", 
                             "42-55 perc. affluent X moderator", 
                             "More than 55 perc. affluent X moderator", 
                             "Lagged DV",
                             "Lagged DV",
                             "Lagged DV",
                             "Lagged DV"))


texreg(list(passive.lis.motivationlead_tfs01, voteprez2.lis.motivationlead_tfs01, campaign.lis.motivationlead_tfs01, protest.lis.motivationlead_tfs01, elected.lis.motivationlead_tfs01 ),
       caption = "The Effect of Campus Affluence on Motivation to Lead (Individual)", 
       custom.model.names = c("Passive Engagement", "Voting", "Campaigning", "Protesting", "Elected S.G."),
       caption.above = TRUE, digits = 3, stars = c(0.001, 0.01, 0.05),
       custom.coef.names = c("Intercept", 
                             "Lagged DV", 
                             "22-32 perc. affluent", 
                             "32-42 perc. affluent", 
                             "42-55 perc. affluent", 
                             "More than 55 perc. affluent", 
                             "moderator",
                             "High standardized test score",
                             "Missing test score",
                             "Female",
                             "Asian",
                             "Latino",
                             "Black",
                             "Other race",
                             "Jewish",
                             "Catholic",
                             "Evangelical",
                             "Other or no religion",
                             "English second language",
                             "Aged 17 or less",
                             "Aged 19",
                             "Aged 20",
                             "Social science major",
                             "Humanities major",
                             "Science major",
                             "Business major",
                             "Attend to make money",
                             "Proportion high standardized test score",
                             "Proportion Asian",
                             "Proportion Latino ",
                             "Proportion other race ",
                             "Proportion Jewish ",
                             "Proportion Catholic ",
                             "Proportion Evangelical",
                             "Proportion other or no religion",
                             "Proportion English second languages ",
                             "Proportion aged 17 or less",
                             "Proportion aged 19",
                             "Proportion aged 20",
                             "Proportion social science major",
                             "Proportion humanities major",
                             "Proportion science major",
                             "Proportion business major",
                             "Proportion attending to make money",
                             "Mostly female",
                             "Mostly Black",
                             "Large student body",
                             "Public", 
                             "College",
                             "Northeast",
                             "South",
                             "1995",
                             "1996",
                             "1997",
                             "1998",
                             "1999",
                             "2000",
                             "2001",
                             "2002",
                             "2003",
                             "2004",
                             "2005",
                             "2006",
                             "2007",
                             "22-32 perc. affluent X moderator", 
                             "32-42 perc. affluent X moderator", 
                             "42-55 perc. affluent X moderator", 
                             "More than 55 perc. affluent X moderator", 
                             "Lagged DV",
                             "Lagged DV",
                             "Lagged DV",
                             "Lagged DV"))

#####################
# Appendix Table 16 #
#####################

texreg(list(passive.lis.academcomp_tfs01, voteprez2.lis.academcomp_tfs01, campaign.lis.academcomp_tfs01, protest.lis.academcomp_tfs01, elected.lis.academcomp_tfs01, orglead.lis.academcomp_tfs01 ),
       caption = "The Effect of Campus Affluence on Academic Mechanism (Individual)", 
       custom.model.names = c("Passive Engagement", "Voting", "Campaigning", "Protesting", "Elected S.G.", "Leading Org."),
       caption.above = TRUE, digits = 3, stars = c(0.001, 0.01, 0.05),
       custom.coef.names = c("Intercept", 
                             "Lagged DV", 
                             "22-32 perc. affluent", 
                             "32-42 perc. affluent", 
                             "42-55 perc. affluent", 
                             "More than 55 perc. affluent", 
                             "moderator",
                             "High standardized test score",
                             "Missing test score",
                             "Female",
                             "Asian",
                             "Latino",
                             "Black",
                             "Other race",
                             "Jewish",
                             "Catholic",
                             "Evangelical",
                             "Other or no religion",
                             "English second language",
                             "Aged 17 or less",
                             "Aged 19",
                             "Aged 20",
                             "Social science major",
                             "Humanities major",
                             "Science major",
                             "Business major",
                             "Attend to make money",
                             "Proportion high standardized test score",
                             "Proportion Asian",
                             "Proportion Latino ",
                             "Proportion other race ",
                             "Proportion Jewish ",
                             "Proportion Catholic ",
                             "Proportion Evangelical",
                             "Proportion other or no religion",
                             "Proportion English second languages ",
                             "Proportion aged 17 or less",
                             "Proportion aged 19",
                             "Proportion aged 20",
                             "Proportion social science major",
                             "Proportion humanities major",
                             "Proportion science major",
                             "Proportion business major",
                             "Proportion attending to make money",
                             "Mostly female",
                             "Mostly Black",
                             "Large student body",
                             "Public", 
                             "College",
                             "Northeast",
                             "South",
                             "1995",
                             "1996",
                             "1997",
                             "1998",
                             "1999",
                             "2000",
                             "2001",
                             "2002",
                             "2003",
                             "2004",
                             "2005",
                             "2006",
                             "2007",
                             "2008",
                             "2009",
                             "2010",
                             "2011",
                             "2012",
                             "2013",
                             "22-32 perc. affluent X moderator", 
                             "32-42 perc. affluent X moderator", 
                             "42-55 perc. affluent X moderator", 
                             "More than 55 perc. affluent X moderator", 
                             "Lagged DV",
                             "Lagged DV",
                             "Lagged DV",
                             "Lagged DV"))

#####################
# Appendix Table 17 #
#####################

texreg(list(passive.lis.soccon_tfs01, voteprez2.lis.soccon_tfs01, campaign.lis.soccon_tfs01, protest.lis.soccon_tfs01, elected.lis.soccon_tfs01, orglead.lis.soccon_tfs01 ),
       caption = "The Effect of Campus Affluence on Social Self-Confidence (Individual)", 
       custom.model.names = c("Passive Engagement", "Voting", "Campaigning", "Protesting", "Elected S.G.", "Leading Org."),
       caption.above = TRUE, digits = 3, stars = c(0.001, 0.01, 0.05),
       custom.coef.names = c("Intercept", 
                             "Lagged DV", 
                             "22-32 perc. affluent", 
                             "32-42 perc. affluent", 
                             "42-55 perc. affluent", 
                             "More than 55 perc. affluent", 
                             "moderator",
                             "High standardized test score",
                             "Missing test score",
                             "Female",
                             "Asian",
                             "Latino",
                             "Black",
                             "Other race",
                             "Jewish",
                             "Catholic",
                             "Evangelical",
                             "Other or no religion",
                             "English second language",
                             "Aged 17 or less",
                             "Aged 19",
                             "Aged 20",
                             "Social science major",
                             "Humanities major",
                             "Science major",
                             "Business major",
                             "Attend to make money",
                             "Proportion high standardized test score",
                             "Proportion Asian",
                             "Proportion Latino ",
                             "Proportion other race ",
                             "Proportion Jewish ",
                             "Proportion Catholic ",
                             "Proportion Evangelical",
                             "Proportion other or no religion",
                             "Proportion English second languages ",
                             "Proportion aged 17 or less",
                             "Proportion aged 19",
                             "Proportion aged 20",
                             "Proportion social science major",
                             "Proportion humanities major",
                             "Proportion science major",
                             "Proportion business major",
                             "Proportion attending to make money",
                             "Mostly female",
                             "Mostly Black",
                             "Large student body",
                             "Public", 
                             "College",
                             "Northeast",
                             "South",
                             "1995",
                             "1996",
                             "1997",
                             "1998",
                             "1999",
                             "2000",
                             "2001",
                             "2002",
                             "2003",
                             "2004",
                             "2005",
                             "2006",
                             "2007",
                             "2008",
                             "2009",
                             "2010",
                             "2011",
                             "2012",
                             "2013",
                             "22-32 perc. affluent X moderator", 
                             "32-42 perc. affluent X moderator", 
                             "42-55 perc. affluent X moderator", 
                             "More than 55 perc. affluent X moderator", 
                             "Lagged DV",
                             "Lagged DV",
                             "Lagged DV",
                             "Lagged DV"))

texreg(list(passive.lis.soccon_tfs_cohort01, voteprez2.lis.soccon_tfs_cohort01, campaign.lis.soccon_tfs_cohort01, protest.lis.soccon_tfs_cohort01, elected.lis.soccon_tfs_cohort01, orglead.lis.soccon_tfs_cohort01 ),
       caption = "The Effect of Campus Affluence on Social Self-Confidence (Aggregate)", 
       custom.model.names = c("Passive Engagement", "Voting", "Campaigning", "Protesting", "Elected S.G.", "Leading Org."),
       caption.above = TRUE, digits = 3, stars = c(0.001, 0.01, 0.05),
       custom.coef.names = c("Intercept", 
                             "Lagged DV", 
                             "22-32 perc. affluent", 
                             "32-42 perc. affluent", 
                             "42-55 perc. affluent", 
                             "More than 55 perc. affluent", 
                             "moderator",
                             "High standardized test score",
                             "Missing test score",
                             "Female",
                             "Asian",
                             "Latino",
                             "Black",
                             "Other race",
                             "Jewish",
                             "Catholic",
                             "Evangelical",
                             "Other or no religion",
                             "English second language",
                             "Aged 17 or less",
                             "Aged 19",
                             "Aged 20",
                             "Social science major",
                             "Humanities major",
                             "Science major",
                             "Business major",
                             "Attend to make money",
                             "Proportion high standardized test score",
                             "Proportion Asian",
                             "Proportion Latino ",
                             "Proportion other race ",
                             "Proportion Jewish ",
                             "Proportion Catholic ",
                             "Proportion Evangelical",
                             "Proportion other or no religion",
                             "Proportion English second languages ",
                             "Proportion aged 17 or less",
                             "Proportion aged 19",
                             "Proportion aged 20",
                             "Proportion social science major",
                             "Proportion humanities major",
                             "Proportion science major",
                             "Proportion business major",
                             "Proportion attending to make money",
                             "Mostly female",
                             "Mostly Black",
                             "Large student body",
                             "Public", 
                             "College",
                             "Northeast",
                             "South",
                             "1995",
                             "1996",
                             "1997",
                             "1998",
                             "1999",
                             "2000",
                             "2001",
                             "2002",
                             "2003",
                             "2004",
                             "2005",
                             "2006",
                             "2007",
                             "2008",
                             "2009",
                             "2010",
                             "2011",
                             "2012",
                             "2013",
                             "22-32 perc. affluent X moderator", 
                             "32-42 perc. affluent X moderator", 
                             "42-55 perc. affluent X moderator", 
                             "More than 55 perc. affluent X moderator", 
                             "Lagged DV",
                             "Lagged DV",
                             "Lagged DV",
                             "Lagged DV"))

#####################
# Appendix Table 18 #
#####################

texreg(list(passive.lis.collaidratio01, voting.lis.collaidratio01, campaign.lis.collaidratio01, protest.lis.collaidratio01, elected.lis.collaidratio01 ),
       caption = "The Effect of Campus Affluence on Financial Mechanism(Individual)", 
       custom.model.names = c("Passive Engagement", "Voting", "Campaigning", "Protesting", "Elected S.G."),
       caption.above = TRUE, digits = 3, stars = c(0.001, 0.01, 0.05),
       custom.coef.names = c("Intercept", 
                             "Lagged DV", 
                             "22-32 perc. affluent", 
                             "32-42 perc. affluent", 
                             "42-55 perc. affluent", 
                             "More than 55 perc. affluent", 
                             "moderator",
                             "High standardized test score",
                             "Missing test score",
                             "Female",
                             "Asian",
                             "Latino",
                             "Black",
                             "Other race",
                             "Jewish",
                             "Catholic",
                             "Evangelical",
                             "Other or no religion",
                             "English second language",
                             "Aged 17 or less",
                             "Aged 19",
                             "Aged 20",
                             "Social science major",
                             "Humanities major",
                             "Science major",
                             "Business major",
                             "Attend to make money",
                             "Proportion high standardized test score",
                             "Proportion Asian",
                             "Proportion Latino ",
                             "Proportion other race ",
                             "Proportion Jewish ",
                             "Proportion Catholic ",
                             "Proportion Evangelical",
                             "Proportion other or no religion",
                             "Proportion English second languages ",
                             "Proportion aged 17 or less",
                             "Proportion aged 19",
                             "Proportion aged 20",
                             "Proportion social science major",
                             "Proportion humanities major",
                             "Proportion science major",
                             "Proportion business major",
                             "Proportion attending to make money",
                             "Mostly female",
                             "Mostly Black",
                             "Large student body",
                             "Public", 
                             "College",
                             "Northeast",
                             "South",
                             "1995",
                             "1996",
                             "1997",
                             "1998",
                             "1999",
                             "2000",
                             "2001",
                             "2002",
                             "2003",
                             "2004",
                             "2005",
                             "2006",
                             "22-32 perc. affluent X moderator", 
                             "32-42 perc. affluent X moderator", 
                             "42-55 perc. affluent X moderator", 
                             "More than 55 perc. affluent X moderator", 
                             "Lagged DV",
                             "Lagged DV",
                             "Lagged DV",
                             "Lagged DV"))

texreg(list(passive.lis.fincon01, voting.lis.fincon01, campaign.lis.fincon01, protest.lis.fincon01, elected.lis.fincon01, orglead.lis.fincon01 ),
       caption = "The Effect of Campus Affluence on Financial Mechanism (Individual)", 
       custom.model.names = c("Passive Engagement", "Voting", "Campaigning", "Protesting", "Elected S.G.", "Leading Org."),
       caption.above = TRUE, digits = 3, stars = c(0.001, 0.01, 0.05),
       custom.coef.names = c("Intercept", 
                             "Lagged DV", 
                             "22-32 perc. affluent", 
                             "32-42 perc. affluent", 
                             "42-55 perc. affluent", 
                             "More than 55 perc. affluent", 
                             "moderator",
                             "High standardized test score",
                             "Missing test score",
                             "Female",
                             "Asian",
                             "Latino",
                             "Black",
                             "Other race",
                             "Jewish",
                             "Catholic",
                             "Evangelical",
                             "Other or no religion",
                             "English second language",
                             "Aged 17 or less",
                             "Aged 19",
                             "Aged 20",
                             "Social science major",
                             "Humanities major",
                             "Science major",
                             "Business major",
                             "Attend to make money",
                             "Proportion high standardized test score",
                             "Proportion Asian",
                             "Proportion Latino ",
                             "Proportion other race ",
                             "Proportion Jewish ",
                             "Proportion Catholic ",
                             "Proportion Evangelical",
                             "Proportion other or no religion",
                             "Proportion English second languages ",
                             "Proportion aged 17 or less",
                             "Proportion aged 19",
                             "Proportion aged 20",
                             "Proportion social science major",
                             "Proportion humanities major",
                             "Proportion science major",
                             "Proportion business major",
                             "Proportion attending to make money",
                             "Mostly female",
                             "Mostly Black",
                             "Large student body",
                             "Public", 
                             "College",
                             "Northeast",
                             "South",
                             "1995",
                             "1996",
                             "1997",
                             "1998",
                             "1999",
                             "2000",
                             "2001",
                             "2002",
                             "2003",
                             "2004",
                             "2005",
                             "2006",
                             "2007",
                             "2008",
                             "2009",
                             "2010",
                             "2011",
                             "2012",
                             "2013",
                             "22-32 perc. affluent X moderator", 
                             "32-42 perc. affluent X moderator", 
                             "42-55 perc. affluent X moderator", 
                             "More than 55 perc. affluent X moderator", 
                             "Lagged DV",
                             "Lagged DV",
                             "Lagged DV",
                             "Lagged DV"))

texreg(list(passive.lis.fincon.lis.school01, voting.lis.fincon.lis.school01, campaign.lis.fincon.lis.school01, protest.lis.fincon.lis.school01, elected.lis.fincon.lis.school01, orglead.lis.fincon.lis.school01 ),
       caption = "The Effect of Campus Affluence on Financial Mechanism (Aggregate)", 
       custom.model.names = c("Passive Engagement", "Voting", "Campaigning", "Protesting", "Elected S.G.", "Leading Org."),
       caption.above = TRUE, digits = 3, stars = c(0.001, 0.01, 0.05),
       custom.coef.names = c("Intercept", 
                             "Lagged DV", 
                             "22-32 perc. affluent", 
                             "32-42 perc. affluent", 
                             "42-55 perc. affluent", 
                             "More than 55 perc. affluent", 
                             "moderator",
                             "High standardized test score",
                             "Missing test score",
                             "Female",
                             "Asian",
                             "Latino",
                             "Black",
                             "Other race",
                             "Jewish",
                             "Catholic",
                             "Evangelical",
                             "Other or no religion",
                             "English second language",
                             "Aged 17 or less",
                             "Aged 19",
                             "Aged 20",
                             "Social science major",
                             "Humanities major",
                             "Science major",
                             "Business major",
                             "Attend to make money",
                             "Proportion high standardized test score",
                             "Proportion Asian",
                             "Proportion Latino ",
                             "Proportion other race ",
                             "Proportion Jewish ",
                             "Proportion Catholic ",
                             "Proportion Evangelical",
                             "Proportion other or no religion",
                             "Proportion English second languages ",
                             "Proportion aged 17 or less",
                             "Proportion aged 19",
                             "Proportion aged 20",
                             "Proportion social science major",
                             "Proportion humanities major",
                             "Proportion science major",
                             "Proportion business major",
                             "Proportion attending to make money",
                             "Mostly female",
                             "Mostly Black",
                             "Large student body",
                             "Public", 
                             "College",
                             "Northeast",
                             "South",
                             "1995",
                             "1996",
                             "1997",
                             "1998",
                             "1999",
                             "2000",
                             "2001",
                             "2002",
                             "2003",
                             "2004",
                             "2005",
                             "2006",
                             "2007",
                             "2008",
                             "2009",
                             "2010",
                             "2011",
                             "2012",
                             "2013",
                             "22-32 perc. affluent X moderator", 
                             "32-42 perc. affluent X moderator", 
                             "42-55 perc. affluent X moderator", 
                             "More than 55 perc. affluent X moderator", 
                             "Lagged DV",
                             "Lagged DV",
                             "Lagged DV",
                             "Lagged DV"))

#####################
# Appendix Table 19 #
#####################

texreg(list(passive.lis.closedfac, voting.lis.closedfac, campaign.lis.closedfac, protest.lis.closedfac, elected.lis.closedfac, orglead.lis.closedfac ),
       caption = "The Effect of Campus Affluence on Financial Mechanism (Aggregate)", 
       custom.model.names = c("Passive Engagement", "Voting", "Campaigning", "Protesting", "Elected S.G.", "Leading Org."),
       caption.above = TRUE, digits = 3, stars = c(0.001, 0.01, 0.05),
       custom.coef.names = c("Intercept", 
                             "Lagged DV", 
                             "22-32 perc. affluent", 
                             "32-42 perc. affluent", 
                             "42-55 perc. affluent", 
                             "More than 55 perc. affluent", 
                             "moderator",
                             "High standardized test score",
                             "Missing test score",
                             "Female",
                             "Asian",
                             "Latino",
                             "Black",
                             "Other race",
                             "Jewish",
                             "Catholic",
                             "Evangelical",
                             "Other or no religion",
                             "English second language",
                             "Aged 17 or less",
                             "Aged 19",
                             "Aged 20",
                             "Social science major",
                             "Humanities major",
                             "Science major",
                             "Business major",
                             "Attend to make money",
                             "Proportion high standardized test score",
                             "Proportion Asian",
                             "Proportion Latino ",
                             "Proportion other race ",
                             "Proportion Jewish ",
                             "Proportion Catholic ",
                             "Proportion Evangelical",
                             "Proportion other or no religion",
                             "Proportion English second languages ",
                             "Proportion aged 17 or less",
                             "Proportion aged 19",
                             "Proportion aged 20",
                             "Proportion social science major",
                             "Proportion humanities major",
                             "Proportion science major",
                             "Proportion business major",
                             "Proportion attending to make money",
                             "Mostly female",
                             "Mostly Black",
                             "Large student body",
                             "Public", 
                             "College",
                             "Northeast",
                             "South",
                             "1995",
                             "1996",
                             "1997",
                             "1998",
                             "1999",
                             "2000",
                             "2001",
                             "2002",
                             "2003",
                             "2004",
                             "2005",
                             "2006",
                             "2007",
                             "2008",
                             "2009",
                             "2010",
                             "2011",
                             "2012",
                             "2013",
                             "22-32 perc. affluent X moderator", 
                             "32-42 perc. affluent X moderator", 
                             "42-55 perc. affluent X moderator", 
                             "More than 55 perc. affluent X moderator", 
                             "Lagged DV",
                             "Lagged DV",
                             "Lagged DV",
                             "Lagged DV"))

#####################
# Appendix Table 20 #
#####################

# individual level political ideology (conservatism)

passive.lis.ideologytfs01_conserv <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + factor(affcat)*factor(ideologytfs01_conserv) + hitestscore + testscore_na + female +
                                            asian + hispanic + black + othrace + jewish + catholic + evangelical + otherornorelig + notenglishfirst + age17orless +
                                            age19 + age20 + socscitfs + humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                            hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                                            age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + makemoneyvimpper +
                                            mostlyfemale + mostlyblack +  largesb + public + college + neast +  south + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), 
                                          data = data.lis)

voting.lis.ideologytfs01_conserv <- glmer(voteprez2 ~ polaffairs_tfs + factor(affcat)*factor(ideologytfs01_conserv) + hitestscore + testscore_na + female +
                                            asian + hispanic + black + othrace + jewish + catholic + evangelical + otherornorelig + notenglishfirst + age17orless +
                                            age19 + age20 + socscitfs + humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                            hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                                            age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + makemoneyvimpper +
                                            mostlyfemale + mostlyblack +  largesb + public + college + neast +  south + factor(YEAR) + 
                                            (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

campaign.lis.ideologytfs01_conserv <- glmer(campaign_css ~ campaign_tfs + factor(affcat)*factor(ideologytfs01_conserv) + hitestscore + testscore_na + female +
                                              asian + hispanic + black + othrace + jewish + catholic + evangelical + otherornorelig + notenglishfirst + age17orless +
                                              age19 + age20 + socscitfs + humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                              hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                                              age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + makemoneyvimpper +
                                              mostlyfemale + mostlyblack +  largesb + public + college + neast +  south + factor(YEAR) + 
                                              (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

protest.lis.ideologytfs01_conserv <- glmer(protestindex_css ~ protest_tfs + factor(affcat)*factor(ideologytfs01_conserv) + hitestscore + testscore_na + female +
                                             asian + hispanic + black + othrace + jewish + catholic + evangelical + otherornorelig + notenglishfirst + age17orless +
                                             age19 + age20 + socscitfs + humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                             hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                                             age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + makemoneyvimpper +
                                             mostlyfemale + mostlyblack +  largesb + public + college + neast +  south + factor(YEAR) + 
                                             (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

elected.lis.ideologytfs01_conserv <- glmer(elected01_gov ~ commlead_tfs + factor(affcat)*factor(ideologytfs01_conserv) + hitestscore + testscore_na + female +
                                             asian + hispanic + black + othrace + jewish + catholic + evangelical + otherornorelig + notenglishfirst + age17orless +
                                             age19 + age20 + socscitfs + humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                             hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                                             age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + makemoneyvimpper +
                                             mostlyfemale + mostlyblack +  largesb + public + college + neast +  south + factor(YEAR) + 
                                             (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

orglead.lis.ideologytfs01_conserv <- glmer(orglead01 ~ commlead_tfs + factor(affcat)*factor(ideologytfs01_conserv) + hitestscore + testscore_na + female +
                                             asian + hispanic + black + othrace + jewish + catholic + evangelical + otherornorelig + notenglishfirst + age17orless +
                                             age19 + age20 + socscitfs + humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                             hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                                             age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + makemoneyvimpper +
                                             mostlyfemale + mostlyblack +  largesb + public + college + neast +  south + factor(YEAR) + 
                                             (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

# cohort level political ideology (conservatism)

passive.lis.cohortideology01_conserv <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + factor(affcat)*factor(cohortideology01_conserv) + hitestscore + testscore_na + female +
                                               asian + hispanic + black + othrace + jewish + catholic + evangelical + otherornorelig + notenglishfirst + age17orless +
                                               age19 + age20 + socscitfs + humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                               hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                                               age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + makemoneyvimpper +
                                               mostlyfemale + mostlyblack +  largesb + public + college + neast +  south + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), 
                                             data = data.lis)

voting.lis.cohortideology01_conserv <- glmer(voteprez2 ~ polaffairs_tfs + factor(affcat)*factor(cohortideology01_conserv) + hitestscore + testscore_na + female +
                                               asian + hispanic + black + othrace + jewish + catholic + evangelical + otherornorelig + notenglishfirst + age17orless +
                                               age19 + age20 + socscitfs + humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                               hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                                               age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + makemoneyvimpper +
                                               mostlyfemale + mostlyblack +  largesb + public + college + neast +  south + factor(YEAR) + 
                                               (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

campaign.lis.cohortideology01_conserv <- glmer(campaign_css ~ campaign_tfs + factor(affcat)*factor(cohortideology01_conserv) + hitestscore + testscore_na + female +
                                                 asian + hispanic + black + othrace + jewish + catholic + evangelical + otherornorelig + notenglishfirst + age17orless +
                                                 age19 + age20 + socscitfs + humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                                 hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                                                 age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + makemoneyvimpper +
                                                 mostlyfemale + mostlyblack +  largesb + public + college + neast +  south + factor(YEAR) + 
                                                 (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

protest.lis.cohortideology01_conserv <- glmer(protestindex_css ~ protest_tfs + factor(affcat)*factor(cohortideology01_conserv) + hitestscore + testscore_na + female +
                                                asian + hispanic + black + othrace + jewish + catholic + evangelical + otherornorelig + notenglishfirst + age17orless +
                                                age19 + age20 + socscitfs + humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                                hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                                                age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + makemoneyvimpper +
                                                mostlyfemale + mostlyblack +  largesb + public + college + neast +  south + factor(YEAR) + 
                                                (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

elected.lis.cohortideology01_conserv <- glmer(elected01_gov ~ commlead_tfs + factor(affcat)*factor(cohortideology01_conserv) + hitestscore + testscore_na + female +
                                                asian + hispanic + black + othrace + jewish + catholic + evangelical + otherornorelig + notenglishfirst + age17orless +
                                                age19 + age20 + socscitfs + humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                                hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                                                age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + makemoneyvimpper +
                                                mostlyfemale + mostlyblack +  largesb + public + college + neast +  south + factor(YEAR) + 
                                                (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

orglead.lis.cohortideology01_conserv <- glmer(orglead01 ~ commlead_tfs + factor(affcat)*factor(cohortideology01_conserv) + hitestscore + testscore_na + female +
                                                asian + hispanic + black + othrace + jewish + catholic + evangelical + otherornorelig + notenglishfirst + age17orless +
                                                age19 + age20 + socscitfs + humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                                hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                                                age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + makemoneyvimpper +
                                                mostlyfemale + mostlyblack +  largesb + public + college + neast +  south + factor(YEAR) + 
                                                (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

# cohort level first-gen

cor(data.lis$affcat, data.lis$cohortfirstgen01_strict, use = "complete.obs")

passive.lis.cohortfirstgen01_strict <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + factor(affcat)*factor(cohortfirstgen01_strict) + hitestscore + testscore_na + female +
                                              asian + hispanic + black + othrace + jewish + catholic + evangelical + otherornorelig + notenglishfirst + age17orless +
                                              age19 + age20 + socscitfs + humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                              hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                                              age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + makemoneyvimpper +
                                              mostlyfemale + mostlyblack +  largesb + public + college + neast +  south + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), 
                                            data = data.lis)

voting.lis.cohortfirstgen01_strict <- glmer(voteprez2 ~ polaffairs_tfs + factor(affcat)*factor(cohortfirstgen01_strict) + hitestscore + testscore_na + female +
                                              asian + hispanic + black + othrace + jewish + catholic + evangelical + otherornorelig + notenglishfirst + age17orless +
                                              age19 + age20 + socscitfs + humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                              hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                                              age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + makemoneyvimpper +
                                              mostlyfemale + mostlyblack +  largesb + public + college + neast +  south + factor(YEAR) + 
                                              (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

campaign.lis.cohortfirstgen01_strict <- glmer(campaign_css ~ campaign_tfs + factor(affcat)*factor(cohortfirstgen01_strict) + hitestscore + testscore_na + female +
                                                asian + hispanic + black + othrace + jewish + catholic + evangelical + otherornorelig + notenglishfirst + age17orless +
                                                age19 + age20 + socscitfs + humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                                hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                                                age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + makemoneyvimpper +
                                                mostlyfemale + mostlyblack +  largesb + public + college + neast +  south + factor(YEAR) + 
                                                (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

protest.lis.cohortfirstgen01_strict <- glmer(protestindex_css ~ protest_tfs + factor(affcat)*factor(cohortfirstgen01_strict) + hitestscore + testscore_na + female +
                                               asian + hispanic + black + othrace + jewish + catholic + evangelical + otherornorelig + notenglishfirst + age17orless +
                                               age19 + age20 + socscitfs + humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                               hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                                               age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + makemoneyvimpper +
                                               mostlyfemale + mostlyblack +  largesb + public + college + neast +  south + factor(YEAR) + 
                                               (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

elected.lis.cohortfirstgen01_strict <- glmer(elected01_gov ~ commlead_tfs + factor(affcat)*factor(cohortfirstgen01_strict) + hitestscore + testscore_na + female +
                                               asian + hispanic + black + othrace + jewish + catholic + evangelical + otherornorelig + notenglishfirst + age17orless +
                                               age19 + age20 + socscitfs + humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                               hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                                               age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + makemoneyvimpper +
                                               mostlyfemale + mostlyblack +  largesb + public + college + neast +  south + factor(YEAR) + 
                                               (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

orglead.lis.cohortfirstgen01_strict <- glmer(orglead01 ~ commlead_tfs + factor(affcat)*factor(cohortfirstgen01_strict) + hitestscore + testscore_na + female +
                                               asian + hispanic + black + othrace + jewish + catholic + evangelical + otherornorelig + notenglishfirst + age17orless +
                                               age19 + age20 + socscitfs + humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                               hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                                               age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + makemoneyvimpper +
                                               mostlyfemale + mostlyblack +  largesb + public + college + neast +  south + factor(YEAR) + 
                                               (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

# Indivdual level first-gen

cor(data.lis$affcat, data.lis$firstgen_strict, use = "complete.obs", method = "spearman")


passive.lis.firstgen_strict <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + factor(affcat)*factor(firstgen_strict) + hitestscore + testscore_na + female +
                                      asian + hispanic + black + othrace + jewish + catholic + evangelical + otherornorelig + notenglishfirst + age17orless +
                                      age19 + age20 + socscitfs + humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                      hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                                      age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + makemoneyvimpper +
                                      mostlyfemale + mostlyblack +  largesb + public + college + neast +  south + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), 
                                    data = data.lis)

voting.lis.firstgen_strict <- glmer(voteprez2 ~ polaffairs_tfs + factor(affcat)*factor(firstgen_strict) + hitestscore + testscore_na + female +
                                      asian + hispanic + black + othrace + jewish + catholic + evangelical + otherornorelig + notenglishfirst + age17orless +
                                      age19 + age20 + socscitfs + humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                      hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                                      age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + makemoneyvimpper +
                                      mostlyfemale + mostlyblack +  largesb + public + college + neast +  south + factor(YEAR) + 
                                      (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

campaign.lis.firstgen_strict <- glmer(campaign_css ~ campaign_tfs + factor(affcat)*factor(firstgen_strict) + hitestscore + testscore_na + female +
                                        asian + hispanic + black + othrace + jewish + catholic + evangelical + otherornorelig + notenglishfirst + age17orless +
                                        age19 + age20 + socscitfs + humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                        hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                                        age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + makemoneyvimpper +
                                        mostlyfemale + mostlyblack +  largesb + public + college + neast +  south + factor(YEAR) + 
                                        (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

protest.lis.firstgen_strict <- glmer(protestindex_css ~ protest_tfs + factor(affcat)*factor(firstgen_strict) + hitestscore + testscore_na + female +
                                       asian + hispanic + black + othrace + jewish + catholic + evangelical + otherornorelig + notenglishfirst + age17orless +
                                       age19 + age20 + socscitfs + humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                       hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                                       age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + makemoneyvimpper +
                                       mostlyfemale + mostlyblack +  largesb + public + college + neast +  south + factor(YEAR) + 
                                       (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

elected.lis.firstgen_strict <- glmer(elected01_gov ~ commlead_tfs + factor(affcat)*factor(firstgen_strict) + hitestscore + testscore_na + female +
                                       asian + hispanic + black + othrace + jewish + catholic + evangelical + otherornorelig + notenglishfirst + age17orless +
                                       age19 + age20 + socscitfs + humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                       hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                                       age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + makemoneyvimpper +
                                       mostlyfemale + mostlyblack +  largesb + public + college + neast +  south + factor(YEAR) + 
                                       (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

orglead.lis.firstgen_strict <- glmer(orglead01 ~ commlead_tfs + factor(affcat)*factor(firstgen_strict) + hitestscore + testscore_na + female +
                                       asian + hispanic + black + othrace + jewish + catholic + evangelical + otherornorelig + notenglishfirst + age17orless +
                                       age19 + age20 + socscitfs + humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                       hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                                       age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + makemoneyvimpper +
                                       mostlyfemale + mostlyblack +  largesb + public + college + neast +  south + factor(YEAR) + 
                                       (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

## college aid ratio at cohort level (from HERI data)

passive.lis.collaid_lis_ratio_cohrts_scld01 <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + factor(affcat)*factor(collaid_lis_ratio_cohrts_scld01 ) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + 
                                                      catholic + evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                                                      hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                                                      age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                                                      largesb + public + college + neast + south + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), data = data.lis)  


voteprez2.lis.collaid_lis_ratio_cohrts_scld01 <- glmer(voteprez2 ~ polaffairs_tfs + factor(affcat)*factor(collaid_lis_ratio_cohrts_scld01 ) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                                                         otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                                                         hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                                                         socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                                                         factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

campaign.lis.collaid_lis_ratio_cohrts_scld01 <- glmer(campaign_css ~ campaign_tfs + factor(affcat)*factor(collaid_lis_ratio_cohrts_scld01 ) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                                                        otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                                                        hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                                                        socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                                                        factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

elected.lis.collaid_lis_ratio_cohrts_scld01 <- glmer(elected01_gov ~ commlead_tfs + factor(affcat)*factor(collaid_lis_ratio_cohrts_scld01 ) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                                                       otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                                                       hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                                                       socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                                                       factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

orglead.lis.collaid_lis_ratio_cohrts_scld01<- glmer(orglead01 ~ commlead_tfs + factor(affcat)*factor(collaid_lis_ratio_cohrts_scld01 ) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                                                      otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                                                      hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                                                      socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                                                      factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

protest.lis.collaid_lis_ratio_cohrts_scld01 <-  glmer(protestindex_css ~ protest_tfs + factor(affcat)*factor(collaid_lis_ratio_cohrts_scld01 ) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                                                        otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                                                        hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                                                        socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                                                        factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

cor(data.lis$affcat, data.lis$firstgen_strict, use = "complete.obs", method = "spearman")
texreg(list(passive.lis.ideologytfs01_conserv, voting.lis.ideologytfs01_conserv, campaign.lis.ideologytfs01_conserv, protest.lis.ideologytfs01_conserv, elected.lis.ideologytfs01_conserv, orglead.lis.ideologytfs01_conserv ),
       caption = "The Effect of Campus Affluence on Additional Tests (Individual)", 
       custom.model.names = c("Passive Engagement", "Voting", "Campaigning", "Protesting", "Elected S.G.", "Leading Org."),
       caption.above = TRUE, digits = 3, stars = c(0.001, 0.01, 0.05),
       custom.coef.names = c("Intercept", 
                             "Lagged DV", 
                             "22-32 perc. affluent", 
                             "32-42 perc. affluent", 
                             "42-55 perc. affluent", 
                             "More than 55 perc. affluent", 
                             "moderator",
                             "High standardized test score",
                             "Missing test score",
                             "Female",
                             "Asian",
                             "Latino",
                             "Black",
                             "Other race",
                             "Jewish",
                             "Catholic",
                             "Evangelical",
                             "Other or no religion",
                             "English second language",
                             "Aged 17 or less",
                             "Aged 19",
                             "Aged 20",
                             "Social science major",
                             "Humanities major",
                             "Science major",
                             "Business major",
                             "Attend to make money",
                             "Proportion high standardized test score",
                             "Proportion Asian",
                             "Proportion Latino ",
                             "Proportion other race ",
                             "Proportion Jewish ",
                             "Proportion Catholic ",
                             "Proportion Evangelical",
                             "Proportion other or no religion",
                             "Proportion English second languages ",
                             "Proportion aged 17 or less",
                             "Proportion aged 19",
                             "Proportion aged 20",
                             "Proportion social science major",
                             "Proportion humanities major",
                             "Proportion science major",
                             "Proportion business major",
                             "Proportion attending to make money",
                             "Mostly female",
                             "Mostly Black",
                             "Large student body",
                             "Public", 
                             "College",
                             "Northeast",
                             "South",
                             "1995",
                             "1996",
                             "1997",
                             "1998",
                             "1999",
                             "2000",
                             "2001",
                             "2002",
                             "2003",
                             "2004",
                             "2005",
                             "2006",
                             "2007",
                             "2008",
                             "2009",
                             "2010",
                             "2011",
                             "2012",
                             "2013",
                             "22-32 perc. affluent X moderator", 
                             "32-42 perc. affluent X moderator", 
                             "42-55 perc. affluent X moderator", 
                             "More than 55 perc. affluent X moderator", 
                             "Lagged DV",
                             "Lagged DV",
                             "Lagged DV",
                             "Lagged DV"))

cor(data.lis$affcat, data.lis$cohortideology01_conserv, use = "complete.obs", method = "spearman")


texreg(list(passive.lis.cohortideology01_conserv, voting.lis.cohortideology01_conserv, campaign.lis.cohortideology01_conserv, protest.lis.cohortideology01_conserv, elected.lis.cohortideology01_conserv, orglead.lis.cohortideology01_conserv ),
       caption = "The Effect of Campus Affluence on Additional Tests(Aggregate)", 
       custom.model.names = c("Passive Engagement", "Voting", "Campaigning", "Protesting", "Elected S.G.", "Leading Org."),
       caption.above = TRUE, digits = 3, stars = c(0.001, 0.01, 0.05),
       custom.coef.names = c("Intercept", 
                             "Lagged DV", 
                             "22-32 perc. affluent", 
                             "32-42 perc. affluent", 
                             "42-55 perc. affluent", 
                             "More than 55 perc. affluent", 
                             "moderator",
                             "High standardized test score",
                             "Missing test score",
                             "Female",
                             "Asian",
                             "Latino",
                             "Black",
                             "Other race",
                             "Jewish",
                             "Catholic",
                             "Evangelical",
                             "Other or no religion",
                             "English second language",
                             "Aged 17 or less",
                             "Aged 19",
                             "Aged 20",
                             "Social science major",
                             "Humanities major",
                             "Science major",
                             "Business major",
                             "Attend to make money",
                             "Proportion high standardized test score",
                             "Proportion Asian",
                             "Proportion Latino ",
                             "Proportion other race ",
                             "Proportion Jewish ",
                             "Proportion Catholic ",
                             "Proportion Evangelical",
                             "Proportion other or no religion",
                             "Proportion English second languages ",
                             "Proportion aged 17 or less",
                             "Proportion aged 19",
                             "Proportion aged 20",
                             "Proportion social science major",
                             "Proportion humanities major",
                             "Proportion science major",
                             "Proportion business major",
                             "Proportion attending to make money",
                             "Mostly female",
                             "Mostly Black",
                             "Large student body",
                             "Public", 
                             "College",
                             "Northeast",
                             "South",
                             "1995",
                             "1996",
                             "1997",
                             "1998",
                             "1999",
                             "2000",
                             "2001",
                             "2002",
                             "2003",
                             "2004",
                             "2005",
                             "2006",
                             "2007",
                             "2008",
                             "2009",
                             "2010",
                             "2011",
                             "2012",
                             "2013",
                             "22-32 perc. affluent X moderator", 
                             "32-42 perc. affluent X moderator", 
                             "42-55 perc. affluent X moderator", 
                             "More than 55 perc. affluent X moderator", 
                             "Lagged DV",
                             "Lagged DV",
                             "Lagged DV",
                             "Lagged DV"))

texreg(list(passive.lis.firstgen_strict, voting.lis.firstgen_strict, campaign.lis.firstgen_strict, protest.lis.firstgen_strict, elected.lis.firstgen_strict, orglead.lis.firstgen_strict ),
       caption = "The Effect of Campus Affluence on Additional Tests(Individual)", 
       custom.model.names = c("Passive Engagement", "Voting", "Campaigning", "Protesting", "Elected S.G.", "Leading Org."),
       caption.above = TRUE, digits = 3, stars = c(0.001, 0.01, 0.05),
       custom.coef.names = c("Intercept", 
                             "Lagged DV", 
                             "22-32 perc. affluent", 
                             "32-42 perc. affluent", 
                             "42-55 perc. affluent", 
                             "More than 55 perc. affluent", 
                             "moderator",
                             "High standardized test score",
                             "Missing test score",
                             "Female",
                             "Asian",
                             "Latino",
                             "Black",
                             "Other race",
                             "Jewish",
                             "Catholic",
                             "Evangelical",
                             "Other or no religion",
                             "English second language",
                             "Aged 17 or less",
                             "Aged 19",
                             "Aged 20",
                             "Social science major",
                             "Humanities major",
                             "Science major",
                             "Business major",
                             "Attend to make money",
                             "Proportion high standardized test score",
                             "Proportion Asian",
                             "Proportion Latino ",
                             "Proportion other race ",
                             "Proportion Jewish ",
                             "Proportion Catholic ",
                             "Proportion Evangelical",
                             "Proportion other or no religion",
                             "Proportion English second languages ",
                             "Proportion aged 17 or less",
                             "Proportion aged 19",
                             "Proportion aged 20",
                             "Proportion social science major",
                             "Proportion humanities major",
                             "Proportion science major",
                             "Proportion business major",
                             "Proportion attending to make money",
                             "Mostly female",
                             "Mostly Black",
                             "Large student body",
                             "Public", 
                             "College",
                             "Northeast",
                             "South",
                             "1995",
                             "1996",
                             "1997",
                             "1998",
                             "1999",
                             "2000",
                             "2001",
                             "2002",
                             "2003",
                             "2004",
                             "2005",
                             "2006",
                             "2007",
                             "2008",
                             "2009",
                             "2010",
                             "2011",
                             "2012",
                             "2013",
                             "22-32 perc. affluent X moderator", 
                             "32-42 perc. affluent X moderator", 
                             "42-55 perc. affluent X moderator", 
                             "More than 55 perc. affluent X moderator", 
                             "Lagged DV",
                             "Lagged DV",
                             "Lagged DV",
                             "Lagged DV"))

texreg(list(passive.lis.cohortfirstgen01_strict, voting.lis.cohortfirstgen01_strict, campaign.lis.cohortfirstgen01_strict, protest.lis.cohortfirstgen01_strict, elected.lis.cohortfirstgen01_strict, orglead.lis.cohortfirstgen01_strict ),
       caption = "The Effect of Campus Affluence on Additional Tests (Aggregate)", 
       custom.model.names = c("Passive Engagement", "Voting", "Campaigning", "Protesting", "Elected S.G.", "Leading Org."),
       caption.above = TRUE, digits = 3, stars = c(0.001, 0.01, 0.05),
       custom.coef.names = c("Intercept", 
                             "Lagged DV", 
                             "22-32 perc. affluent", 
                             "32-42 perc. affluent", 
                             "42-55 perc. affluent", 
                             "More than 55 perc. affluent", 
                             "moderator",
                             "High standardized test score",
                             "Missing test score",
                             "Female",
                             "Asian",
                             "Latino",
                             "Black",
                             "Other race",
                             "Jewish",
                             "Catholic",
                             "Evangelical",
                             "Other or no religion",
                             "English second language",
                             "Aged 17 or less",
                             "Aged 19",
                             "Aged 20",
                             "Social science major",
                             "Humanities major",
                             "Science major",
                             "Business major",
                             "Attend to make money",
                             "Proportion high standardized test score",
                             "Proportion Asian",
                             "Proportion Latino ",
                             "Proportion other race ",
                             "Proportion Jewish ",
                             "Proportion Catholic ",
                             "Proportion Evangelical",
                             "Proportion other or no religion",
                             "Proportion English second languages ",
                             "Proportion aged 17 or less",
                             "Proportion aged 19",
                             "Proportion aged 20",
                             "Proportion social science major",
                             "Proportion humanities major",
                             "Proportion science major",
                             "Proportion business major",
                             "Proportion attending to make money",
                             "Mostly female",
                             "Mostly Black",
                             "Large student body",
                             "Public", 
                             "College",
                             "Northeast",
                             "South",
                             "1995",
                             "1996",
                             "1997",
                             "1998",
                             "1999",
                             "2000",
                             "2001",
                             "2002",
                             "2003",
                             "2004",
                             "2005",
                             "2006",
                             "2007",
                             "2008",
                             "2009",
                             "2010",
                             "2011",
                             "2012",
                             "2013",
                             "22-32 perc. affluent X moderator", 
                             "32-42 perc. affluent X moderator", 
                             "42-55 perc. affluent X moderator", 
                             "More than 55 perc. affluent X moderator", 
                             "Lagged DV",
                             "Lagged DV",
                             "Lagged DV",
                             "Lagged DV"))

texreg(list(passive.lis.collaid_lis_ratio_cohrts_scld01, voteprez2.lis.collaid_lis_ratio_cohrts_scld01, campaign.lis.collaid_lis_ratio_cohrts_scld01, protest.lis.collaid_lis_ratio_cohrts_scld01, elected.lis.collaid_lis_ratio_cohrts_scld01),
       caption = "The Effect of Campus Affluence on Institutional Practices (Aggregate)", 
       custom.model.names = c("Passive Engagement", "Voting", "Campaigning", "Protesting", "Elected S.G."),
       caption.above = TRUE, digits = 3, stars = c(0.001, 0.01, 0.05))

#####################
# Appendix Table 21 #
#####################

# See code for main paper Table 2 above

#####################
# Appendix Table 22 #
#####################

fulldata.r <- rbind(data.lis, data.mis, data.his)

fulldata.r$parinc2 <- factor(fulldata.r$parinc, levels = c("Low-Income",
                                                           "Middle-Income",
                                                           "High-Income"))

binary.r <- fulldata.r[fulldata.r$affcat %in% c(1,5) & !is.na(fulldata.r$affcat),]

# Top and bottom affluence categories

passive.int <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + factor(affcat)*parinc2 + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                      evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                      hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                      age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                      largesb + public + college + neast + south + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), data = binary.r)  
summary(passive.int)

protest.int <-  glmer(protestindex_css ~ protest_tfs + factor(affcat)*parinc2 + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                        otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                        hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                        socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                        factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = binary.r)
summary(protest.int)

orglead.int <- glmer(orglead01 ~ commlead_tfs + factor(affcat)*parinc2 + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                       otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                       hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                       socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                       factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = binary.r)
summary(orglead.int)   

voteprez2.int <- glmer(voteprez2 ~ polaffairs_tfs + factor(affcat)*parinc2 + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                         otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                         hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                         socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                         factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = binary.r)
summary(voteprez2.int)

campaign.int <- glmer(campaign_css ~ campaign_tfs + factor(affcat)*parinc2 + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                        otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                        hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                        socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                        factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = binary.r)
summary(campaign.int)

elected.int <- glmer(elected01_gov ~ commlead_tfs + factor(affcat)*parinc2 + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                       otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                       hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                       socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                       factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = binary.r)

texreg(list(passive.int, voteprez2.int, campaign.int, protest.int, elected.int, orglead.int),
       caption = "Interaction Models", 
       custom.model.names = c("Passive Engagement", "Voting", "Campaigning", "Protesting", "Elected SG", "Leading Org."),
       caption.above = TRUE, digits = 3, stars = c(0.001, 0.01, 0.05))

#####################
# Appendix Table 23 #
#####################

passive.black <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + factor(affcat)*black + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic +
                        evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                        hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                        age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                        largesb + public + college + neast + south + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), data = data.lis)  
summary(passive.black)

protest.black <-  glmer(protestindex_css ~ protest_tfs + factor(affcat)*black + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                          otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                          hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                          socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                          factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)
summary(protest.black)

orglead.black <- glmer(orglead01 ~ commlead_tfs + factor(affcat)*black + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                         otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                         hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                         socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                         factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)
summary(orglead.black)   

voteprez2.black <- glmer(voteprez2 ~ polaffairs_tfs + factor(affcat)*black + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                           otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                           hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                           socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                           factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)
summary(voteprez2.black)

campaign.black <- glmer(campaign_css ~ campaign_tfs + factor(affcat)*black + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                          otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                          hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                          socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                          factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)
summary(campaign.black)

elected.black <- glmer(elected01_gov ~ commlead_tfs + factor(affcat)*black + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                         otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                         hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                         socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                         factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

texreg(list(passive.black, voteprez2.black, campaign.black, protest.black, elected.black, orglead.black),
       caption = "Interaction Models", 
       custom.model.names = c("Passive Engagement", "Voting", "Campaigning", "Protesting", "Elected SG", "Leading Org."),
       caption.above = TRUE, digits = 3, stars = c(0.001, 0.01, 0.05))



#####################
# Appendix Table 24 #
#####################

invlogit <- function(x){1/(1+exp(-x))}


#large <- read.dta("attrition_large_limited.dta")
#this is for file that does not limit sample to schools with more than 100 individuals taking the TFS and more than 20 taking the CSS)
#results are based on smaller sample, so only run that here:

small <- read.dta("attrition_small_limited.dta")


#create a few last variables:

small$csstaken<-ifelse(is.na(small$csspresent),0,1) #key

small$ace_year <- paste(small$ACERECODE, small$YEAR, sep=".")


describe(small$hitestscore_x)
describe(small$hitestscore_y)


small$testscore_na <- ifelse(is.na(small$hitestscore_x), 1, 0)
describe(small$testscore_na) 



table(small$affcat)
table(small$affper_x)


small$affcat_tfs <- ifelse(small$affper_x <= .23, 1, 
                           ifelse(small$affper_x > .23 &
                                    small$affper_x <= .33, 2, 
                                  ifelse(small$affper_x > .33 &
                                           small$affper_x <= .43, 3, 
                                         ifelse(small$affper_x > .43 &
                                                  small$affper_x <= .57, 4,
                                                ifelse(small$affper_x > .57, 5, NA)))))

table(small$affcat_tfs, small$affcat)
describe(small$affcat_tfs)



#now, will do the following:

#test logit with only level 1 - predicting if took or not
#test ML logit with level 1 and level 2 - predicting if took or not
#see if matters what years use

#create weights - to make CSS same as TFS

#run main analysis using weights and not using weights


#1 - DV can use passive_index_css - but only obs for panel participants

#2 - I want panel sample to be same as TFS same (when including panel also - ie TFS that COULD take CSS)
#2a - alternatively, maybe make panel participants same as non-panel participants - actually, this is same



#########################

#run models - start with small
#KEY to note - many panel variables are NOT available for TFS dataset! 

table(small$hitestscore_x)

level1_small <- glm(csstaken ~ factor(income_x) + hitestscore_x  + female_x + asian_x + hispanic_x + black_x + othrace_x + jewish_x + catholic_x +
                      evangelical_x + otherornorelig_x  +  makemoneyvimp_x,
                    data=small, family=binomial(), na.action = na.exclude) 
summary(level1_small) 
#removed age and majors and missing test score and not english as first language, rest is there

small$predictlevel1 <- predict(level1_small, type = "response")

describe(small$predictlevel1)


level2_small <-glmer(csstaken ~ factor(income_x) + hitestscore_x  + testscore_na +  female_x + asian_x + hispanic_x + black_x + othrace_x + jewish_x + catholic_x +
                       evangelical_x + otherornorelig_x  +  makemoneyvimp_x  + hitestscoreper_x   + makemoneyvimpper_x + femaleper_x + 
                       asianper_x + hispanicper_x + blackper_x + othraceper_x + catholicper_x + 
                       evangelicalper_x + jewishper_x + otherornoreligper_x + 
                       factor(affcat_tfs) + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), 
                     control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = small, na.action = na.exclude)
summary(level2_small)

small$predictlevel2 <-predict(level2_small, type = "response")
describe(small$predictlevel2)



level2_small_int <-glmer(csstaken ~ hitestscore_x  + testscore_na +  female_x + asian_x + hispanic_x + black_x + othrace_x + jewish_x + catholic_x +
                           evangelical_x + otherornorelig_x  +  makemoneyvimp_x  + hitestscoreper_x   + makemoneyvimpper_x + femaleper_x + 
                           asianper_x + hispanicper_x + blackper_x + othraceper_x + catholicper_x + 
                           evangelicalper_x + jewishper_x + otherornoreligper_x + 
                           factor(income_x)*factor(affcat_tfs) + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), 
                         control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = small, na.action = na.exclude)
summary(level2_small_int)


level2_small_lis <-glmer(csstaken ~  hitestscore_x  + testscore_na +  female_x + asian_x + hispanic_x + black_x + othrace_x + jewish_x + catholic_x +
                           evangelical_x + otherornorelig_x  +  makemoneyvimp_x  + hitestscoreper_x   + makemoneyvimpper_x + femaleper_x + 
                           asianper_x + hispanicper_x + blackper_x + othraceper_x + catholicper_x + 
                           evangelicalper_x + jewishper_x + otherornoreligper_x + 
                           factor(affcat_tfs) + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), 
                         control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = small[small$income_x==1,], na.action = na.exclude)
summary(level2_small_lis)



level2_small_mis <-glmer(csstaken ~  hitestscore_x  + testscore_na +  female_x + asian_x + hispanic_x + black_x + othrace_x + jewish_x + catholic_x +
                           evangelical_x + otherornorelig_x  +  makemoneyvimp_x  + hitestscoreper_x   + makemoneyvimpper_x + femaleper_x + 
                           asianper_x + hispanicper_x + blackper_x + othraceper_x + catholicper_x + 
                           evangelicalper_x + jewishper_x + otherornoreligper_x + 
                           factor(affcat_tfs) + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), 
                         control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = small[small$income_x==2,], na.action = na.exclude)
summary(level2_small_mis)




level2_small_his <-glmer(csstaken ~  hitestscore_x  + testscore_na +  female_x + asian_x + hispanic_x + black_x + othrace_x + jewish_x + catholic_x +
                           evangelical_x + otherornorelig_x  +  makemoneyvimp_x  + hitestscoreper_x   + makemoneyvimpper_x + femaleper_x + 
                           asianper_x + hispanicper_x + blackper_x + othraceper_x + catholicper_x + 
                           evangelicalper_x + jewishper_x + otherornoreligper_x + 
                           factor(affcat_tfs) + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), 
                         control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = small[small$income_x==3,], na.action = na.exclude)
summary(level2_small_his)


#table 22:
texreg(list(level1_small, level2_small, level2_small_int, level2_small_lis, level2_small_mis, level2_small_his),
       caption = "The Effect of Income and Campus Affluence on Taking Senior Year Survey", 
       custom.model.names = c("Individual-level", "Full", "Full", "Low-Income", "Middle-Income", "High-Income"),
       caption.above = TRUE, digits = 3, stars = c(0.001, 0.01, 0.05))



#figures 5 and 6:


small$unique_id <- rownames(small) 
small_lis <- small[small$income_x==1,]
small_mis <- small[small$income_x==2,]
small_his <- small[small$income_x==3,]

small_lis$predictlevel2_lis <- predict(level2_small_lis, type = "response")
describe(small_lis$predictlevel2_lis)

small_mis$predictlevel2_mis <-predict(level2_small_mis, type = "response")
describe(small_mis$predictlevel2_mis)

small_his$predictlevel2_his <-predict(level2_small_his, type = "response")
describe(small_his$predictlevel2_his)


small_lis <- data.frame(subset(small_lis, select=c(unique_id, predictlevel2_lis)))
small_mis <- data.frame(subset(small_mis, select=c(unique_id, predictlevel2_mis)))
small_his <- data.frame(subset(small_his, select=c(unique_id, predictlevel2_his)))

small <- merge(small, small_lis, by = c("unique_id"), all.x = T)
small <- merge(small, small_mis, by = c("unique_id"), all.x = T)
small <- merge(small, small_his, by = c("unique_id"), all.x = T)

small$weights_level2 <- ifelse(small$csstaken == 1, 1/small$predictlevel2, 1/(1-small$predictlevel2))
#coule use this instead, but results below are based on weights obtained within income groups 

small$weights_level2_lis <- ifelse(small$csstaken == 1, 1/small$predictlevel2_lis, 1/(1-small$predictlevel2_lis))
small$weights_level2_mis <- ifelse(small$csstaken == 1, 1/small$predictlevel2_mis, 1/(1-small$predictlevel2_mis))
small$weights_level2_his <- ifelse(small$csstaken == 1, 1/small$predictlevel2_his, 1/(1-small$predictlevel2_his))





#########################
# Level 2 by subgroup, Small #
#########################



describe(small$weights_level2)

passive.lis2 <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + factor(affcat) + hitestscore_y + testscore_na +  female_y +  asian_y +  hispanic_y + black_y +  othrace_y +
                       jewish_y +  catholic_y + evangelical_y + otherornorelig_y + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                       businesstfs + makemoneyvimp_y +  hitestscoreper_y + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                       hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                       makemoneyvimpper_y +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS_y) + (1 | ACERECODE) + (1 | ace_year),
                     data = small[small$csstaken ==1 & small$parinc_y == "Low-Income",], weights=(weights_level2_lis))  


passive.mis2 <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + factor(affcat) + hitestscore_y + testscore_na +  female_y +  asian_y +  hispanic_y + black_y +  othrace_y +
                       jewish_y +  catholic_y + evangelical_y + otherornorelig_y + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                       businesstfs + makemoneyvimp_y +  hitestscoreper_y + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                       hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                       makemoneyvimpper_y +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS_y) + (1 | ACERECODE) + (1 | ace_year),
                     data = small[small$csstaken ==1 & small$parinc_y == "Middle-Income",], weights=(weights_level2_mis))  


passive.his2 <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + factor(affcat) + hitestscore_y + testscore_na +  female_y +  asian_y +  hispanic_y + black_y +  othrace_y +
                       jewish_y +  catholic_y + evangelical_y + otherornorelig_y + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                       businesstfs + makemoneyvimp_y +  hitestscoreper_y + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                       hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                       makemoneyvimpper_y +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS_y) + (1 | ACERECODE) + (1 | ace_year),
                     data = small[small$csstaken ==1 & small$parinc_y == "High-Income",], weights=(weights_level2_his))  

summary(passive.lis2)
summary(passive.mis2)
summary(passive.his2)


modelvars <- c("passive_index_css_avg", "passive_index_tfs_avg", "affcat", "hitestscore_y", "female_y", "asian_y", "hispanic_y", "black_y", "othrace_y",
               "jewish_y", "catholic_y", "evangelical_y", "otherornorelig_y", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs", "makemoneyvimp_y",  "hitestscoreper_y",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper_y", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south", "YEAR_TFS_y", "ACERECODE", "ace_year", "csstaken", "parinc_y")

small2 <- small[complete.cases(small[,modelvars]),]

data.lis.temp  <- small2[small2$csstaken ==1 & small2$parinc_y == "Low-Income" & !is.na(small2$weights_level2_lis),]
data.mis.temp  <- small2[small2$csstaken ==1 & small2$parinc_y == "Middle-Income" & !is.na(small2$weights_level2_mis),]
data.his.temp  <- small2[small2$csstaken ==1 & small2$parinc_y == "High-Income" & !is.na(small2$weights_level2_his),]



passive.lis2.p <- summary(passive.lis2)$coefficients["factor(affcat)5", 5] 


data.lis.temp$affcat <- 1
passive.lis2.pred.1 <- mean(predict(passive.lis2, data.lis.temp, re.form=NULL)) 
data.lis.temp$affcat <- 5
passive.lis2.pred.5 <- mean(predict(passive.lis2, data.lis.temp, re.form=NULL)) 
passive.lis2.eff <- passive.lis2.pred.5 - passive.lis2.pred.1

passive.mis2.p <- summary(passive.mis2)$coefficients["factor(affcat)5",5] 

data.mis.temp$affcat <- 1
passive.mis2.pred.1 <- mean(predict(passive.mis2, data.mis.temp, re.form=NULL)) 
data.mis.temp$affcat <- 5
passive.mis2.pred.5 <- mean(predict(passive.mis2, data.mis.temp, re.form=NULL)) 
passive.mis2.eff <- passive.mis2.pred.5 - passive.mis2.pred.1

passive.his2.p <- summary(passive.his2)$coefficients["factor(affcat)5",5] 

data.his.temp$affcat <- 1
passive.his2.pred.1 <- mean(predict(passive.his2, data.his.temp, re.form=NULL)) 
data.his.temp$affcat <- 5
passive.his2.pred.5 <- mean(predict(passive.his2, data.his.temp, re.form=NULL)) 
passive.his2.eff <- passive.his2.pred.5 - passive.his2.pred.1



##########
# Voting #
##########


table(small$voteprez2)
table(small$polaffairs_tfs)


voteprez.lis2 <- glmer(voteprez2 ~ polaffairs_tfs +  factor(affcat) + hitestscore_y + testscore_na +  female_y +  asian_y +  hispanic_y + black_y +  othrace_y +
                         jewish_y +  catholic_y + evangelical_y + otherornorelig_y + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                         businesstfs + makemoneyvimp_y +  hitestscoreper_y + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                         hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                         makemoneyvimpper_y +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS_y) + (1 | ACERECODE) + (1 | ace_year),
                       family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                       data = small[small$csstaken ==1 & small$parinc_y == "Low-Income",], weights=(weights_level2_lis))  




voteprez.mis2 <- glmer(voteprez2 ~ polaffairs_tfs +  factor(affcat) + hitestscore_y + testscore_na +  female_y +  asian_y +  hispanic_y + black_y +  othrace_y +
                         jewish_y +  catholic_y + evangelical_y + otherornorelig_y + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                         businesstfs + makemoneyvimp_y +  hitestscoreper_y + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                         hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                         makemoneyvimpper_y +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS_y) + (1 | ACERECODE) + (1 | ace_year),
                       family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                       data = small[small$csstaken ==1 & small$parinc_y == "Middle-Income",], weights=(weights_level2_mis))  


voteprez.his2 <- glmer(voteprez2 ~ polaffairs_tfs +  factor(affcat) + hitestscore_y + testscore_na +  female_y +  asian_y +  hispanic_y + black_y +  othrace_y +
                         jewish_y +  catholic_y + evangelical_y + otherornorelig_y + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                         businesstfs + makemoneyvimp_y +  hitestscoreper_y + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                         hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                         makemoneyvimpper_y +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS_y) + (1 | ACERECODE) + (1 | ace_year),
                       family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                       data = small[small$csstaken ==1 & small$parinc_y == "High-Income",], weights=(weights_level2_his))  


modelvars <- c("voteprez2", "polaffairs_tfs", "affcat", "hitestscore_y", "female_y", "asian_y", "hispanic_y", "black_y", "othrace_y",
               "jewish_y", "catholic_y", "evangelical_y", "otherornorelig_y", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs", "makemoneyvimp_y",  "hitestscoreper_y",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper_y", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south", "YEAR_TFS_y", "ACERECODE", "ace_year", "csstaken", "parinc_y")


small2 <- small[complete.cases(small[,modelvars]),]

data.lis.temp  <- small2[small2$csstaken ==1 & small2$parinc_y == "Low-Income" & !is.na(small2$weights_level2_lis),]
data.mis.temp  <- small2[small2$csstaken ==1 & small2$parinc_y == "Middle-Income" & !is.na(small2$weights_level2_mis),]
data.his.temp  <- small2[small2$csstaken ==1 & small2$parinc_y == "High-Income" & !is.na(small2$weights_level2_his),]



voteprez.lis2.p <- summary(voteprez.lis2)$coefficients["factor(affcat)5",4] 

data.lis.temp$affcat <- 1
voteprez.lis2.pred.1 <- mean(predict(voteprez.lis2, data.lis.temp, re.form=NULL, type = "response")) 
data.lis.temp$affcat <- 5
voteprez.lis2.pred.5 <- mean(predict(voteprez.lis2, data.lis.temp, re.form=NULL, type = "response")) 
voteprez.lis2.eff <- voteprez.lis2.pred.5 - voteprez.lis2.pred.1



voteprez.mis2.p <- summary(voteprez.mis2)$coefficients["factor(affcat)5",4] 

data.mis.temp$affcat <- 1
voteprez.mis2.pred.1 <- mean(predict(voteprez.mis2, data.mis.temp, re.form=NULL, type = "response")) 
data.mis.temp$affcat <- 5
voteprez.mis2.pred.5 <- mean(predict(voteprez.mis2, data.mis.temp, re.form=NULL, type = "response")) 
voteprez.mis2.eff <- voteprez.mis2.pred.5 - voteprez.mis2.pred.1


voteprez.his2.p <- summary(voteprez.his2)$coefficients["factor(affcat)5",4] 

data.his.temp$affcat <- 1
voteprez.his2.pred.1 <- mean(predict(voteprez.his2, data.his.temp, re.form=NULL, type = "response")) 
data.his.temp$affcat <- 5
voteprez.his2.pred.5 <- mean(predict(voteprez.his2, data.his.temp, re.form=NULL, type = "response")) 
voteprez.his2.eff <- voteprez.his2.pred.5 - voteprez.his2.pred.1



###############
# Campaigning #
###############

table(small$campaign_css)
table(small$campaign_tfs)


campaign.lis2 <- glmer(campaign_css ~ campaign_tfs + factor(affcat) + hitestscore_y + testscore_na +  female_y +  asian_y +  hispanic_y + black_y +  othrace_y +
                         jewish_y +  catholic_y + evangelical_y + otherornorelig_y + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                         businesstfs + makemoneyvimp_y +  hitestscoreper_y + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                         hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                         makemoneyvimpper_y +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS_y) + (1 | ACERECODE) + (1 | ace_year),
                       family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                       data = small[small$csstaken ==1 & small$parinc_y == "Low-Income",], weights=(weights_level2_lis))  


# Middle-Income

campaign.mis2 <- glmer(campaign_css ~ campaign_tfs + factor(affcat) + hitestscore_y + testscore_na +  female_y +  asian_y +  hispanic_y + black_y +  othrace_y +
                         jewish_y +  catholic_y + evangelical_y + otherornorelig_y + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                         businesstfs + makemoneyvimp_y +  hitestscoreper_y + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                         hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                         makemoneyvimpper_y +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS_y) + (1 | ACERECODE) + (1 | ace_year),
                       family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                       data = small[small$csstaken ==1 & small$parinc_y == "Middle-Income",], weights=(weights_level2_mis))  


# High-Income

campaign.his2 <- glmer(campaign_css ~ campaign_tfs + factor(affcat) + hitestscore_y + testscore_na +  female_y +  asian_y +  hispanic_y + black_y +  othrace_y +
                         jewish_y +  catholic_y + evangelical_y + otherornorelig_y + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                         businesstfs + makemoneyvimp_y +  hitestscoreper_y + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                         hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                         makemoneyvimpper_y +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS_y) + (1 | ACERECODE) + (1 | ace_year),
                       family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                       data = small[small$csstaken ==1 & small$parinc_y == "High-Income",], weights=(weights_level2_his))  



modelvars <- c("campaign_css", "campaign_tfs", "affcat", "hitestscore_y", "female_y", "asian_y", "hispanic_y", "black_y", "othrace_y",
               "jewish_y", "catholic_y", "evangelical_y", "otherornorelig_y", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs", "makemoneyvimp_y",  "hitestscoreper_y",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper_y", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south", "YEAR_TFS_y", "ACERECODE", "ace_year", "csstaken", "parinc_y")


small2 <- small[complete.cases(small[,modelvars]),]

data.lis.temp  <- small2[small2$csstaken ==1 & small2$parinc_y == "Low-Income" & !is.na(small2$weights_level2_lis),]
data.mis.temp  <- small2[small2$csstaken ==1 & small2$parinc_y == "Middle-Income" & !is.na(small2$weights_level2_mis),]
data.his.temp  <- small2[small2$csstaken ==1 & small2$parinc_y == "High-Income" & !is.na(small2$weights_level2_his),]



campaign.lis2.p <- summary(campaign.lis2)$coefficients["factor(affcat)5",4] 

data.lis.temp$affcat <- 1
campaign.lis2.pred.1 <- mean(predict(campaign.lis2, data.lis.temp, re.form=NULL, type = "response")) 
data.lis.temp$affcat <- 5
campaign.lis2.pred.5 <- mean(predict(campaign.lis2, data.lis.temp, re.form=NULL, type = "response")) 
campaign.lis2.eff <- campaign.lis2.pred.5 - campaign.lis2.pred.1


campaign.mis2.p <- summary(campaign.mis2)$coefficients["factor(affcat)5",4] 

data.mis.temp$affcat <- 1
campaign.mis2.pred.1 <- mean(predict(campaign.mis2, data.mis.temp, re.form=NULL, type = "response")) 
data.mis.temp$affcat <- 5
campaign.mis2.pred.5 <- mean(predict(campaign.mis2, data.mis.temp, re.form=NULL, type = "response")) 
campaign.mis2.eff <- campaign.mis2.pred.5 - campaign.mis2.pred.1


campaign.his2.p <- summary(campaign.his2)$coefficients["factor(affcat)5",4] 

data.his.temp$affcat <- 1
campaign.his2.pred.1 <- mean(predict(campaign.his2, data.his.temp, re.form=NULL, type = "response")) 
data.his.temp$affcat <- 5
campaign.his2.pred.5 <- mean(predict(campaign.his2, data.his.temp, re.form=NULL, type = "response")) 
campaign.his2.eff <- campaign.his2.pred.5 - campaign.his2.pred.1



#############################
# Elected to Student Office #
#############################

table(small$elected01_gov)
table(small$commlead_tfs)

elected.lis2 <- glmer(elected01_gov ~ commlead_tfs + factor(affcat) + hitestscore_y + testscore_na +  female_y +  asian_y +  hispanic_y + black_y +  othrace_y +
                        jewish_y +  catholic_y + evangelical_y + otherornorelig_y + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                        businesstfs + makemoneyvimp_y +  hitestscoreper_y + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                        hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                        makemoneyvimpper_y +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS_y) + (1 | ACERECODE) + (1 | ace_year),
                      family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                      data = small[small$csstaken ==1 & small$parinc_y == "Low-Income",], weights=(weights_level2_lis))  



# Middle-Income

elected.mis2 <- glmer(elected01_gov ~ commlead_tfs + factor(affcat) + hitestscore_y + testscore_na +  female_y +  asian_y +  hispanic_y + black_y +  othrace_y +
                        jewish_y +  catholic_y + evangelical_y + otherornorelig_y + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                        businesstfs + makemoneyvimp_y +  hitestscoreper_y + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                        hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                        makemoneyvimpper_y +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS_y) + (1 | ACERECODE) + (1 | ace_year),
                      family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                      data = small[small$csstaken ==1 & small$parinc_y == "Middle-Income",], weights=(weights_level2_mis))  



# High-Income

elected.his2 <- glmer(elected01_gov ~ commlead_tfs + factor(affcat) + hitestscore_y + testscore_na +  female_y +  asian_y +  hispanic_y + black_y +  othrace_y +
                        jewish_y +  catholic_y + evangelical_y + otherornorelig_y + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                        businesstfs + makemoneyvimp_y +  hitestscoreper_y + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                        hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                        makemoneyvimpper_y +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS_y) + (1 | ACERECODE) + (1 | ace_year),
                      family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                      data = small[small$csstaken ==1 & small$parinc_y == "High-Income",], weights=(weights_level2_his))  



modelvars <- c("elected01_gov", "commlead_tfs", "affcat", "hitestscore_y", "female_y", "asian_y", "hispanic_y", "black_y", "othrace_y",
               "jewish_y", "catholic_y", "evangelical_y", "otherornorelig_y", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs", "makemoneyvimp_y",  "hitestscoreper_y",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper_y", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south", "YEAR_TFS_y", "ACERECODE", "ace_year", "csstaken", "parinc_y")


small2 <- small[complete.cases(small[,modelvars]),]

data.lis.temp  <- small2[small2$csstaken ==1 & small2$parinc_y == "Low-Income" & !is.na(small2$weights_level2_lis),]
data.mis.temp  <- small2[small2$csstaken ==1 & small2$parinc_y == "Middle-Income" & !is.na(small2$weights_level2_mis),]
data.his.temp  <- small2[small2$csstaken ==1 & small2$parinc_y == "High-Income" & !is.na(small2$weights_level2_his),]




elected.lis2.p <- summary(elected.lis2)$coefficients["factor(affcat)5",4] 

data.lis.temp$affcat <- 1
elected.lis2.pred.1 <- mean(predict(elected.lis2, data.lis.temp, re.form=NULL, type = "response")) 
data.lis.temp$affcat <- 5
elected.lis2.pred.5 <- mean(predict(elected.lis2, data.lis.temp, re.form=NULL, type = "response")) 
elected.lis2.eff <- elected.lis2.pred.5 - elected.lis2.pred.1


elected.mis2.p <- summary(elected.mis2)$coefficients["factor(affcat)5",4] 

data.mis.temp$affcat <- 1
elected.mis2.pred.1 <- mean(predict(elected.mis2, data.mis.temp, re.form=NULL, type = "response")) 
data.mis.temp$affcat <- 5
elected.mis2.pred.5 <- mean(predict(elected.mis2, data.mis.temp, re.form=NULL, type = "response")) 
elected.mis2.eff <- elected.mis2.pred.5 - elected.mis2.pred.1


elected.his2.p <- summary(elected.his2)$coefficients["factor(affcat)5",4] 

data.his.temp$affcat <- 1
elected.his2.pred.1 <- mean(predict(elected.his2, data.his.temp, re.form=NULL, type = "response")) 
data.his.temp$affcat <- 5
elected.his2.pred.5 <- mean(predict(elected.his2, data.his.temp, re.form=NULL, type = "response")) 
elected.his2.eff <- elected.his2.pred.5 - elected.his2.pred.1



########################################
# Protest Index 
#########################################

table(small$protestindex_css)
table(small$protest_tfs)

# Low-Income

protest.lis2 <- glmer(protestindex_css ~ protest_tfs + factor(affcat) + hitestscore_y + testscore_na +  female_y +  asian_y +  hispanic_y + black_y +  othrace_y +
                        jewish_y +  catholic_y + evangelical_y + otherornorelig_y + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                        businesstfs + makemoneyvimp_y +  hitestscoreper_y + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                        hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                        makemoneyvimpper_y +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS_y) + (1 | ACERECODE) + (1 | ace_year),
                      family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                      data = small[small$csstaken ==1 & small$parinc_y == "Low-Income",], weights=(weights_level2_lis))


# Middle-Income

protest.mis2 <- glmer(protestindex_css ~ protest_tfs + factor(affcat) + hitestscore_y + testscore_na +  female_y +  asian_y +  hispanic_y + black_y +  othrace_y +
                        jewish_y +  catholic_y + evangelical_y + otherornorelig_y + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                        businesstfs + makemoneyvimp_y +  hitestscoreper_y + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                        hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                        makemoneyvimpper_y +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS_y) + (1 | ACERECODE) + (1 | ace_year),
                      family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                      data = small[small$csstaken ==1 & small$parinc_y == "Middle-Income",], weights=(weights_level2_mis)) 


# High-Income

protest.his2 <- glmer(protestindex_css ~ protest_tfs + factor(affcat) + hitestscore_y + testscore_na +  female_y +  asian_y +  hispanic_y + black_y +  othrace_y +
                        jewish_y +  catholic_y + evangelical_y + otherornorelig_y + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                        businesstfs + makemoneyvimp_y +  hitestscoreper_y + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                        hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                        makemoneyvimpper_y +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS_y) + (1 | ACERECODE) + (1 | ace_year),
                      family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                      data = small[small$csstaken ==1 & small$parinc_y == "High-Income",], weights=(weights_level2_his))  



modelvars <- c("protestindex_css", "protest_tfs", "affcat", "hitestscore_y", "female_y", "asian_y", "hispanic_y", "black_y", "othrace_y",
               "jewish_y", "catholic_y", "evangelical_y", "otherornorelig_y", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs", "makemoneyvimp_y",  "hitestscoreper_y",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper_y", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south", "YEAR_TFS_y", "ACERECODE", "ace_year", "csstaken", "parinc_y")


small2 <- small[complete.cases(small[,modelvars]),]

data.lis.temp  <- small2[small2$csstaken ==1 & small2$parinc_y == "Low-Income" & !is.na(small2$weights_level2_lis),]
data.mis.temp  <- small2[small2$csstaken ==1 & small2$parinc_y == "Middle-Income" & !is.na(small2$weights_level2_mis),]
data.his.temp  <- small2[small2$csstaken ==1 & small2$parinc_y == "High-Income" & !is.na(small2$weights_level2_his),]

protest.lis2.p <- summary(protest.lis2)$coefficients["factor(affcat)5",4] 

data.lis.temp$affcat <- 1
protest.lis2.pred.1 <- mean(predict(protest.lis2, data.lis.temp, re.form=NULL, type = "response")) 
data.lis.temp$affcat <- 5
protest.lis2.pred.5 <- mean(predict(protest.lis2, data.lis.temp, re.form=NULL, type = "response")) 
protest.lis2.eff <- protest.lis2.pred.5 - protest.lis2.pred.1


protest.mis2.p <- summary(protest.mis2)$coefficients["factor(affcat)5",4] 

data.mis.temp$affcat <- 1
protest.mis2.pred.1 <- mean(predict(protest.mis2, data.mis.temp, re.form=NULL, type = "response")) 
data.mis.temp$affcat <- 5
protest.mis2.pred.5 <- mean(predict(protest.mis2, data.mis.temp, re.form=NULL, type = "response")) 
protest.mis2.eff <- protest.mis2.pred.5 - protest.mis2.pred.1


protest.his2.p <- summary(protest.his2)$coefficients["factor(affcat)5",4] 

data.his.temp$affcat <- 1
protest.his2.pred.1 <- mean(predict(protest.his2, data.his.temp, re.form=NULL, type = "response")) 
data.his.temp$affcat <- 5
protest.his2.pred.5 <- mean(predict(protest.his2, data.his.temp, re.form=NULL, type = "response")) 
protest.his2.eff <- protest.his2.pred.5 - protest.his2.pred.1





#################################
# Create Predicted Effects Plot - Figure 5
#################################

data2 = data.frame (variable = c("Protest Involvement", "Protest Involvement", "Protest Involvement",
                                 "Passive Engagement Index", "Passive Engagement Index", "Passive Engagement Index",
                                 "Vote in National Election", "Vote in National Election", "Vote in National Election",
                                 "Participate in Campaign", "Participate in Campaign", "Participate in Campaign",
                                 "Elected to Student Government", "Elected to Student Government", "Elected to Student Government"),
                    parinc= c("Low",
                              "Middle",
                              "High"),
                    effect = c(protest.lis2.eff, protest.mis2.eff, protest.his2.eff,
                               passive.lis2.eff, passive.mis2.eff, passive.his2.eff,
                               voteprez.lis2.eff, voteprez.mis2.eff, voteprez.his2.eff,
                               campaign.lis2.eff, campaign.mis2.eff, campaign.his2.eff,
                               elected.lis2.eff, elected.mis2.eff, elected.his2.eff),
                    sig = c(protest.lis2.p, protest.mis2.p, protest.his2.p,
                            passive.lis2.p, passive.mis2.p, passive.his2.p,
                            voteprez.lis2.p, voteprez.mis2.p, voteprez.his2.p,
                            campaign.lis2.p, campaign.mis2.p, campaign.his2.p,
                            elected.lis2.p, elected.mis2.p, elected.his2.p)) 

data2$sig <- ifelse(data2$sig >= .05, "n.s.",
                    ifelse(data2$sig < .05 &
                             data2$sig >= .01, "*",
                           ifelse(data2$sig < .01 &
                                    data2$sig >= .001, "**",
                                  ifelse(data2$sig < .001, "***", NA))))

data2$parinc <- factor(data2$parinc , levels =c("Low", "Middle","High"))


p1 <- ggplot(data2[1:6,], aes(x=parinc, y=effect*100, fill=parinc)) +
  facet_grid(.~variable) +
  geom_bar(stat="identity") +
  ylab("Percent Point Effect") +
  xlab("Parental Income") +
  guides(fill=FALSE) +
  theme_bw() +
  theme(text = element_text(size=22)) +
  geom_hline(yintercept=0, linetype = "dashed") +
  scale_y_continuous(limits=c(-10,16)) +
  geom_text(aes(x=parinc, y=ifelse(sig=="n.s.", .8, .4), 
                label=sig), 
            position = position_dodge(width=1)) 

p2 <- ggplot(data2[7:15,], aes(x=parinc, y=effect*100, fill=parinc)) +
  facet_grid(.~variable) +
  geom_bar(stat="identity") +
  ylab("Percent Point Effect") +
  xlab("Parental Income") +
  guides(fill=FALSE) +
  theme_bw() +
  theme(text = element_text(size=22)) +
  geom_hline(yintercept=0, linetype = "dashed") +
  scale_y_continuous(limits=c(-20,20)) +
  geom_text(aes(x=parinc, y=ifelse(sig=="n.s.", .8, .4), 
                label=sig), 
            position = position_dodge(width=1)) 

grid.arrange(p1, p2)





######original data but with years restricted

csscohort2 <- read.dta("csscohort_final.dta") 


passive.lis3 <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + factor(affcat) + hitestscore + testscore_na +  female +  asian +  hispanic + black +  othrace +
                       jewish +  catholic + evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                       businesstfs + makemoneyvimp +  hitestscoreper + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                       hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                       makemoneyvimpper +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS) + (1 | ACERECODE) + (1 | ace_year),
                     data = csscohort2[csscohort2$YEAR_TFS <= 1999 & csscohort$parinc == "Low-Income",])


passive.mis3 <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + factor(affcat) + hitestscore + testscore_na +  female +  asian +  hispanic + black +  othrace +
                       jewish +  catholic + evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                       businesstfs + makemoneyvimp +  hitestscoreper + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                       hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                       makemoneyvimpper +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS) + (1 | ACERECODE) + (1 | ace_year),
                     data = csscohort2[csscohort2$YEAR_TFS <= 1999 & csscohort$parinc == "Middle-Income",])


passive.his3 <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + factor(affcat) + hitestscore + testscore_na +  female +  asian +  hispanic + black +  othrace +
                       jewish +  catholic + evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                       businesstfs + makemoneyvimp +  hitestscoreper + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                       hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                       makemoneyvimpper +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS) + (1 | ACERECODE) + (1 | ace_year),
                     data = csscohort2[csscohort2$YEAR_TFS <= 1999 & csscohort$parinc == "High-Income",])


modelvars <- c("passive_index_css_avg", "passive_index_tfs_avg", "affcat", "hitestscore", "female", "asian", "hispanic", "black", "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs", "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south", "YEAR_TFS", "ACERECODE", "ace_year",  "parinc")

csscohort2 <- csscohort[complete.cases(csscohort[,modelvars]),]

data.lis.temp  <- csscohort2[csscohort2$YEAR_TFS <= 1999 & csscohort$parinc == "Low-Income",]
data.mis.temp  <- csscohort2[csscohort2$YEAR_TFS <= 1999 & csscohort$parinc == "Middle-Income",]
data.his.temp  <- csscohort2[csscohort2$YEAR_TFS <= 1999 & csscohort$parinc == "High-Income",]



passive.lis3.p <- summary(passive.lis3)$coefficients["factor(affcat)5", 5] 


data.lis.temp$affcat <- 1
passive.lis3.pred.1 <- mean(predict(passive.lis3, data.lis.temp, re.form=NULL)) 
data.lis.temp$affcat <- 5
passive.lis3.pred.5 <- mean(predict(passive.lis3, data.lis.temp, re.form=NULL)) 
passive.lis3.eff <- passive.lis3.pred.5 - passive.lis3.pred.1

passive.mis3.p <- summary(passive.mis3)$coefficients["factor(affcat)5",5] 

data.mis.temp$affcat <- 1
passive.mis3.pred.1 <- mean(predict(passive.mis3, data.mis.temp, re.form=NULL)) 
data.mis.temp$affcat <- 5
passive.mis3.pred.5 <- mean(predict(passive.mis3, data.mis.temp, re.form=NULL)) 
passive.mis3.eff <- passive.mis3.pred.5 - passive.mis3.pred.1

passive.his3.p <- summary(passive.his3)$coefficients["factor(affcat)5",5] 

data.his.temp$affcat <- 1
passive.his3.pred.1 <- mean(predict(passive.his3, data.his.temp, re.form=NULL)) 
data.his.temp$affcat <- 5
passive.his3.pred.5 <- mean(predict(passive.his3, data.his.temp, re.form=NULL)) 
passive.his3.eff <- passive.his3.pred.5 - passive.his3.pred.1



##########
# Voting #
##########


table(small$voteprez2)
table(small$polaffairs_tfs)


voteprez.lis3 <- glmer(voteprez2 ~ polaffairs_tfs +  factor(affcat) + hitestscore + testscore_na +  female +  asian +  hispanic + black +  othrace +
                         jewish +  catholic + evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                         businesstfs + makemoneyvimp +  hitestscoreper + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                         hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                         makemoneyvimpper +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS) + (1 | ACERECODE) + (1 | ace_year),
                       family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                       data = csscohort2[csscohort2$YEAR_TFS <= 1999 & csscohort$parinc == "Low-Income",])




voteprez.mis3 <- glmer(voteprez2 ~ polaffairs_tfs +  factor(affcat) + hitestscore + testscore_na +  female +  asian +  hispanic + black +  othrace +
                         jewish +  catholic + evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                         businesstfs + makemoneyvimp +  hitestscoreper + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                         hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                         makemoneyvimpper +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS) + (1 | ACERECODE) + (1 | ace_year),
                       family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                       data = csscohort2[csscohort2$YEAR_TFS <= 1999 & csscohort$parinc == "Middle-Income",])


voteprez.his3 <- glmer(voteprez2 ~ polaffairs_tfs +  factor(affcat) + hitestscore + testscore_na +  female +  asian +  hispanic + black +  othrace +
                         jewish +  catholic + evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                         businesstfs + makemoneyvimp +  hitestscoreper + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                         hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                         makemoneyvimpper +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS) + (1 | ACERECODE) + (1 | ace_year),
                       family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                       data = csscohort2[csscohort2$YEAR_TFS <= 1999 & csscohort$parinc == "High-Income",])


modelvars <- c("voteprez2", "polaffairs_tfs", "affcat", "hitestscore", "female", "asian", "hispanic", "black", "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs", "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south", "YEAR_TFS", "ACERECODE", "ace_year", "parinc")


csscohort2 <- csscohort[complete.cases(csscohort[,modelvars]),]

data.lis.temp  <- csscohort2[csscohort2$YEAR_TFS <= 1999 & csscohort$parinc == "Low-Income",]
data.mis.temp  <- csscohort2[csscohort2$YEAR_TFS <= 1999 & csscohort$parinc == "Middle-Income",]
data.his.temp  <- csscohort2[csscohort2$YEAR_TFS <= 1999 & csscohort$parinc == "High-Income",]




voteprez.lis3.p <- summary(voteprez.lis3)$coefficients["factor(affcat)5",4] 

data.lis.temp$affcat <- 1
voteprez.lis3.pred.1 <- mean(predict(voteprez.lis3, data.lis.temp, re.form=NULL, type = "response")) 
data.lis.temp$affcat <- 5
voteprez.lis3.pred.5 <- mean(predict(voteprez.lis3, data.lis.temp, re.form=NULL, type = "response")) 
voteprez.lis3.eff <- voteprez.lis3.pred.5 - voteprez.lis3.pred.1



voteprez.mis3.p <- summary(voteprez.mis3)$coefficients["factor(affcat)5",4] 

data.mis.temp$affcat <- 1
voteprez.mis3.pred.1 <- mean(predict(voteprez.mis3, data.mis.temp, re.form=NULL, type = "response")) 
data.mis.temp$affcat <- 5
voteprez.mis3.pred.5 <- mean(predict(voteprez.mis3, data.mis.temp, re.form=NULL, type = "response")) 
voteprez.mis3.eff <- voteprez.mis3.pred.5 - voteprez.mis3.pred.1


voteprez.his3.p <- summary(voteprez.his3)$coefficients["factor(affcat)5",4] 

data.his.temp$affcat <- 1
voteprez.his3.pred.1 <- mean(predict(voteprez.his3, data.his.temp, re.form=NULL, type = "response")) 
data.his.temp$affcat <- 5
voteprez.his3.pred.5 <- mean(predict(voteprez.his3, data.his.temp, re.form=NULL, type = "response")) 
voteprez.his3.eff <- voteprez.his3.pred.5 - voteprez.his3.pred.1



###############
# Campaigning #
###############

table(small$campaign_css)
table(small$campaign_tfs)


campaign.lis3 <- glmer(campaign_css ~ campaign_tfs + factor(affcat) + hitestscore + testscore_na +  female +  asian +  hispanic + black +  othrace +
                         jewish +  catholic + evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                         businesstfs + makemoneyvimp +  hitestscoreper + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                         hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                         makemoneyvimpper +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS) + (1 | ACERECODE) + (1 | ace_year),
                       family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                       data = csscohort2[csscohort2$YEAR_TFS <= 1999 & csscohort$parinc == "Low-Income",])


# Middle-Income

campaign.mis3 <- glmer(campaign_css ~ campaign_tfs + factor(affcat) + hitestscore + testscore_na +  female +  asian +  hispanic + black +  othrace +
                         jewish +  catholic + evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                         businesstfs + makemoneyvimp +  hitestscoreper + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                         hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                         makemoneyvimpper +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS) + (1 | ACERECODE) + (1 | ace_year),
                       family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                       data = csscohort2[csscohort2$YEAR_TFS <= 1999 & csscohort$parinc == "Middle-Income",])


# High-Income

campaign.his3 <- glmer(campaign_css ~ campaign_tfs + factor(affcat) + hitestscore + testscore_na +  female +  asian +  hispanic + black +  othrace +
                         jewish +  catholic + evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                         businesstfs + makemoneyvimp +  hitestscoreper + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                         hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                         makemoneyvimpper +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS) + (1 | ACERECODE) + (1 | ace_year),
                       family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                       data = csscohort2[csscohort2$YEAR_TFS <= 1999 & csscohort$parinc == "High-Income",])



modelvars <- c("campaign_css", "campaign_tfs", "affcat", "hitestscore", "female", "asian", "hispanic", "black", "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs", "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south", "YEAR_TFS", "ACERECODE", "ace_year", "parinc")


csscohort2 <- csscohort[complete.cases(csscohort[,modelvars]),]

data.lis.temp  <- csscohort2[csscohort2$YEAR_TFS <= 1999 & csscohort$parinc == "Low-Income",]
data.mis.temp  <- csscohort2[csscohort2$YEAR_TFS <= 1999 & csscohort$parinc == "Middle-Income",]
data.his.temp  <- csscohort2[csscohort2$YEAR_TFS <= 1999 & csscohort$parinc == "High-Income",]


campaign.lis3.p <- summary(campaign.lis3)$coefficients["factor(affcat)5",4] 

data.lis.temp$affcat <- 1
campaign.lis3.pred.1 <- mean(predict(campaign.lis3, data.lis.temp, re.form=NULL, type = "response")) 
data.lis.temp$affcat <- 5
campaign.lis3.pred.5 <- mean(predict(campaign.lis3, data.lis.temp, re.form=NULL, type = "response")) 
campaign.lis3.eff <- campaign.lis3.pred.5 - campaign.lis3.pred.1


campaign.mis3.p <- summary(campaign.mis3)$coefficients["factor(affcat)5",4] 

data.mis.temp$affcat <- 1
campaign.mis3.pred.1 <- mean(predict(campaign.mis3, data.mis.temp, re.form=NULL, type = "response")) 
data.mis.temp$affcat <- 5
campaign.mis3.pred.5 <- mean(predict(campaign.mis3, data.mis.temp, re.form=NULL, type = "response")) 
campaign.mis3.eff <- campaign.mis3.pred.5 - campaign.mis3.pred.1


campaign.his3.p <- summary(campaign.his3)$coefficients["factor(affcat)5",4] 

data.his.temp$affcat <- 1
campaign.his3.pred.1 <- mean(predict(campaign.his3, data.his.temp, re.form=NULL, type = "response")) 
data.his.temp$affcat <- 5
campaign.his3.pred.5 <- mean(predict(campaign.his3, data.his.temp, re.form=NULL, type = "response")) 
campaign.his3.eff <- campaign.his3.pred.5 - campaign.his3.pred.1



#############################
# Elected to Student Office #
#############################

table(small$elected01_gov)
table(small$commlead_tfs)

elected.lis3 <- glmer(elected01_gov ~ commlead_tfs + factor(affcat) + hitestscore + testscore_na +  female +  asian +  hispanic + black +  othrace +
                        jewish +  catholic + evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                        businesstfs + makemoneyvimp +  hitestscoreper + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                        hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                        makemoneyvimpper +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS) + (1 | ACERECODE) + (1 | ace_year),
                      family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                      data = csscohort2[csscohort2$YEAR_TFS <= 1999 & csscohort$parinc == "Low-Income",])



# Middle-Income

elected.mis3 <- glmer(elected01_gov ~ commlead_tfs + factor(affcat) + hitestscore + testscore_na +  female +  asian +  hispanic + black +  othrace +
                        jewish +  catholic + evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                        businesstfs + makemoneyvimp +  hitestscoreper + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                        hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                        makemoneyvimpper +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS) + (1 | ACERECODE) + (1 | ace_year),
                      family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                      data = csscohort2[csscohort2$YEAR_TFS <= 1999 & csscohort$parinc == "Middle-Income",])



# High-Income

elected.his3 <- glmer(elected01_gov ~ commlead_tfs + factor(affcat) + hitestscore + testscore_na +  female +  asian +  hispanic + black +  othrace +
                        jewish +  catholic + evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                        businesstfs + makemoneyvimp +  hitestscoreper + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                        hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                        makemoneyvimpper +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS) + (1 | ACERECODE) + (1 | ace_year),
                      family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                      data = csscohort2[csscohort2$YEAR_TFS <= 1999 & csscohort$parinc == "High-Income",])



modelvars <- c("elected01_gov", "commlead_tfs", "affcat", "hitestscore", "female", "asian", "hispanic", "black", "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs", "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south", "YEAR_TFS", "ACERECODE", "ace_year", "parinc")



csscohort2 <- csscohort[complete.cases(csscohort[,modelvars]),]

data.lis.temp  <- csscohort2[csscohort2$YEAR_TFS <= 1999 & csscohort$parinc == "Low-Income",]
data.mis.temp  <- csscohort2[csscohort2$YEAR_TFS <= 1999 & csscohort$parinc == "Middle-Income",]
data.his.temp  <- csscohort2[csscohort2$YEAR_TFS <= 1999 & csscohort$parinc == "High-Income",]




elected.lis3.p <- summary(elected.lis3)$coefficients["factor(affcat)5",4] 

data.lis.temp$affcat <- 1
elected.lis3.pred.1 <- mean(predict(elected.lis3, data.lis.temp, re.form=NULL, type = "response")) 
data.lis.temp$affcat <- 5
elected.lis3.pred.5 <- mean(predict(elected.lis3, data.lis.temp, re.form=NULL, type = "response")) 
elected.lis3.eff <- elected.lis3.pred.5 - elected.lis3.pred.1


elected.mis3.p <- summary(elected.mis3)$coefficients["factor(affcat)5",4] 

data.mis.temp$affcat <- 1
elected.mis3.pred.1 <- mean(predict(elected.mis3, data.mis.temp, re.form=NULL, type = "response")) 
data.mis.temp$affcat <- 5
elected.mis3.pred.5 <- mean(predict(elected.mis3, data.mis.temp, re.form=NULL, type = "response")) 
elected.mis3.eff <- elected.mis3.pred.5 - elected.mis3.pred.1


elected.his3.p <- summary(elected.his3)$coefficients["factor(affcat)5",4] 

data.his.temp$affcat <- 1
elected.his3.pred.1 <- mean(predict(elected.his3, data.his.temp, re.form=NULL, type = "response")) 
data.his.temp$affcat <- 5
elected.his3.pred.5 <- mean(predict(elected.his3, data.his.temp, re.form=NULL, type = "response")) 
elected.his3.eff <- elected.his3.pred.5 - elected.his3.pred.1




########################################
# Protest Index 
#########################################

table(small$protestindex_css)
table(small$protest_tfs)

# Low-Income

protest.lis3 <- glmer(protestindex_css ~ protest_tfs + factor(affcat) + hitestscore + testscore_na +  female +  asian +  hispanic + black +  othrace +
                        jewish +  catholic + evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                        businesstfs + makemoneyvimp +  hitestscoreper + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                        hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                        makemoneyvimpper +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS) + (1 | ACERECODE) + (1 | ace_year),
                      family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                      data = csscohort2[csscohort2$YEAR_TFS <= 1999 & csscohort$parinc == "Low-Income",])


# Middle-Income

protest.mis3 <- glmer(protestindex_css ~ protest_tfs + factor(affcat) + hitestscore + testscore_na +  female +  asian +  hispanic + black +  othrace +
                        jewish +  catholic + evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                        businesstfs + makemoneyvimp +  hitestscoreper + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                        hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                        makemoneyvimpper +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS) + (1 | ACERECODE) + (1 | ace_year),
                      family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                      data = csscohort2[csscohort2$YEAR_TFS <= 1999 & csscohort$parinc == "Middle-Income",])


# High-Income

protest.his3 <- glmer(protestindex_css ~ protest_tfs + factor(affcat) + hitestscore + testscore_na +  female +  asian +  hispanic + black +  othrace +
                        jewish +  catholic + evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs +
                        businesstfs + makemoneyvimp +  hitestscoreper + hiasianper + hihispanicper + hiothraceper +  hijewishper + hicatholicper + hievangelicalper +
                        hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper +  humantfsper + sciencetfsper + businesstfsper +
                        makemoneyvimpper +  mostlyfemale +  mostlyblack +  largesb + public +   college + neast + south + factor(YEAR_TFS) + (1 | ACERECODE) + (1 | ace_year),
                      family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                      data = csscohort2[csscohort2$YEAR_TFS <= 1999 & csscohort$parinc == "High-Income",])



modelvars <- c("protestindex_css", "protest_tfs", "affcat", "hitestscore", "female", "asian", "hispanic", "black", "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs", "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south", "YEAR_TFS", "ACERECODE", "ace_year", "parinc")



csscohort2 <- csscohort[complete.cases(csscohort[,modelvars]),]

data.lis.temp  <- csscohort2[csscohort2$YEAR_TFS <= 1999 & csscohort$parinc == "Low-Income",]
data.mis.temp  <- csscohort2[csscohort2$YEAR_TFS <= 1999 & csscohort$parinc == "Middle-Income",]
data.his.temp  <- csscohort2[csscohort2$YEAR_TFS <= 1999 & csscohort$parinc == "High-Income",]



protest.lis3.p <- summary(protest.lis3)$coefficients["factor(affcat)5",4] 

data.lis.temp$affcat <- 1
protest.lis3.pred.1 <- mean(predict(protest.lis3, data.lis.temp, re.form=NULL, type = "response")) 
data.lis.temp$affcat <- 5
protest.lis3.pred.5 <- mean(predict(protest.lis3, data.lis.temp, re.form=NULL, type = "response")) 
protest.lis3.eff <- protest.lis3.pred.5 - protest.lis3.pred.1


protest.mis3.p <- summary(protest.mis3)$coefficients["factor(affcat)5",4] 

data.mis.temp$affcat <- 1
protest.mis3.pred.1 <- mean(predict(protest.mis3, data.mis.temp, re.form=NULL, type = "response")) 
data.mis.temp$affcat <- 5
protest.mis3.pred.5 <- mean(predict(protest.mis3, data.mis.temp, re.form=NULL, type = "response")) 
protest.mis3.eff <- protest.mis3.pred.5 - protest.mis3.pred.1


protest.his3.p <- summary(protest.his3)$coefficients["factor(affcat)5",4] 

data.his.temp$affcat <- 1
protest.his3.pred.1 <- mean(predict(protest.his3, data.his.temp, re.form=NULL, type = "response")) 
data.his.temp$affcat <- 5
protest.his3.pred.5 <- mean(predict(protest.his3, data.his.temp, re.form=NULL, type = "response")) 
protest.his3.eff <- protest.his3.pred.5 - protest.his3.pred.1





#################################
# Create Predicted Effects Plot - Figure 6
#################################



data2 = data.frame (variable = c("Protest Involvement", "Protest Involvement", "Protest Involvement",
                                 "Passive Engagement Index", "Passive Engagement Index", "Passive Engagement Index",
                                 "Vote in National Election", "Vote in National Election", "Vote in National Election",
                                 "Participate in Campaign", "Participate in Campaign", "Participate in Campaign",
                                 "Elected to Student Government", "Elected to Student Government", "Elected to Student Government"),
                    parinc= c("Low",
                              "Middle",
                              "High"),
                    effect = c(protest.lis3.eff, protest.mis3.eff, protest.his3.eff,
                               passive.lis3.eff, passive.mis3.eff, passive.his3.eff,
                               voteprez.lis3.eff, voteprez.mis3.eff, voteprez.his3.eff,
                               campaign.lis3.eff, campaign.mis3.eff, campaign.his3.eff,
                               elected.lis3.eff, elected.mis3.eff, elected.his3.eff),
                    sig = c(protest.lis3.p, protest.mis3.p, protest.his3.p,
                            passive.lis3.p, passive.mis3.p, passive.his3.p,
                            voteprez.lis3.p, voteprez.mis3.p, voteprez.his3.p,
                            campaign.lis3.p, campaign.mis3.p, campaign.his3.p,
                            elected.lis3.p, elected.mis3.p, elected.his3.p)) 

data2$sig <- ifelse(data2$sig >= .05, "n.s.",
                    ifelse(data2$sig < .05 &
                             data2$sig >= .01, "*",
                           ifelse(data2$sig < .01 &
                                    data2$sig >= .001, "**",
                                  ifelse(data2$sig < .001, "***", NA))))

data2$parinc <- factor(data2$parinc , levels =c("Low", "Middle","High"))


p1 <- ggplot(data2[1:6,], aes(x=parinc, y=effect*100, fill=parinc)) +
  facet_grid(.~variable) +
  geom_bar(stat="identity") +
  ylab("Percent Point Effect") +
  xlab("Parental Income") +
  guides(fill=FALSE) +
  theme_bw() +
  theme(text = element_text(size=22)) +
  geom_hline(yintercept=0, linetype = "dashed") +
  scale_continuous(limits=c(-10,16)) +
  geom_text(aes(x=parinc, y=ifelse(sig=="n.s.", .8, .4), 
                label=sig), 
            position = position_dodge(width=1)) 

p2 <- ggplot(data2[7:15,], aes(x=parinc, y=effect*100, fill=parinc)) +
  facet_grid(.~variable) +
  geom_bar(stat="identity") +
  ylab("Percent Point Effect") +
  xlab("Parental Income") +
  guides(fill=FALSE) +
  theme_bw() +
  theme(text = element_text(size=22)) +
  geom_hline(yintercept=0, linetype = "dashed") +
  scale_continuous(limits=c(-20,20)) +
  geom_text(aes(x=parinc, y=ifelse(sig=="n.s.", .8, .4), 
                label=sig), 
            position = position_dodge(width=1)) 

grid.arrange(p1, p2)








##############################################################
####   left over stuff ######################################
##############################################################


########################
# Moderation # Table 
########################


#School-level loan amount ratio 

cor(data.lis$affcat, data.lis$firstgen_strict, use = "complete.obs", method = "spearman")

cor(data.lis$affcat, data.lis$loanamt_ratio_scaled01, use = "complete.obs", method = "spearman")

passive.lis.loanamt.ratio.scaled01 <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + factor(affcat)*factor(loanamt_ratio_scaled01 ) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + 
                                             catholic + evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp +
                                             hitestscoreper + hiasianper + hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper +
                                             age17orlessper + age19per + age20per + socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +
                                             largesb + public + college + neast + south + factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), data = data.lis)  


voteprez2.lis.loanamt.ratio.scaled01 <- glmer(voteprez2 ~ polaffairs_tfs + factor(affcat)*factor(loanamt_ratio_scaled01 ) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                                                otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                                                hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                                                socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                                                factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)

campaign.lis.loanamt.ratio.scaled01 <- glmer(campaign_css ~ campaign_tfs + factor(affcat)*factor(loanamt_ratio_scaled01 ) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                                               otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                                               hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                                               socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                                               factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)


elected.lis.loanamt.ratio.scaled01 <- glmer(elected01_gov ~ commlead_tfs + factor(affcat)*factor(loanamt_ratio_scaled01 ) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                                              otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                                              hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                                              socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                                              factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)


orglead.lis.loanamt.ratio.scaled01 <- glmer(orglead01 ~ commlead_tfs + factor(affcat)*factor(loanamt_ratio_scaled01 ) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                                              otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                                              hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                                              socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                                              factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)


protest.lis.loanamt.ratio.scaled01 <-  glmer(protestindex_css ~ protest_tfs + factor(affcat)*factor(loanamt_ratio_scaled01 ) + hitestscore +  testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + evangelical + 
                                               otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + humantfs + sciencetfs + businesstfs + makemoneyvimp + hitestscoreper + hiasianper + 
                                               hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + notenglishfirstper + age17orlessper + age19per + age20per +
                                               socscitfsper + humantfsper + sciencetfsper + businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack + largesb + public + college + neast + south + 
                                               factor(YEAR) + (1 | ACERECODE) + (1 | ace_year), family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), data = data.lis)



#####moderation tables


texreg(list(passive.lis.academcomp_tfs_cohort01, voteprez2.lis.academcomp_tfs_cohort01, campaign.lis.academcomp_tfs_cohort01, protest.lis.academcomp_tfs_cohort01, elected.lis.academcomp_tfs_cohort01, orglead.lis.academcomp_tfs_cohort01 ),
       caption = "The Effect of Campus Affluence on Academic Mechanism (Aggregate)", 
       custom.model.names = c("Passive Engagement", "Voting", "Campaigning", "Protesting", "Elected S.G.", "Leading Org."),
       caption.above = TRUE, digits = 3, stars = c(0.001, 0.01, 0.05))


texreg(list(passive.lis.collaidratio.lis.school01, voting.lis.collaidratio.lis.school01, campaign.lis.collaidratio.lis.school01, protest.lis.collaidratio.lis.school01, elected.lis.collaidratio.lis.school01, orglead.lis.collaidratio.lis.school01 ),
       caption = "The Effect of Campus Affluence on Financial Mechanism (Aggregate)", 
       custom.model.names = c("Passive Engagement", "Voting", "Campaigning", "Protesting", "Elected S.G.", "Leading Org."),
       caption.above = TRUE, digits = 3, stars = c(0.001, 0.01, 0.05))


texreg(list(passive.lis.loanamt.ratio.scaled01, voteprez2.lis.loanamt.ratio.scaled01, campaign.lis.loanamt.ratio.scaled01, protest.lis.loanamt.ratio.scaled01, elected.lis.loanamt.ratio.scaled01, orglead.lis.loanamt.ratio.scaled01 ),
       caption = "The Effect of Campus Affluence on Financial Mechanism (Aggregate)", 
       custom.model.names = c("Passive Engagement", "Voting", "Campaigning", "Protesting", "Elected S.G.", "Leading Org."),
       caption.above = TRUE, digits = 3, stars = c(0.001, 0.01, 0.05),
       custom.coef.names = c("Intercept", 
                             "Lagged DV", 
                             "22-32 perc. affluent", 
                             "32-42 perc. affluent", 
                             "42-55 perc. affluent", 
                             "More than 55 perc. affluent", 
                             "moderator",
                             "High standardized test score",
                             "Missing test score",
                             "Female",
                             "Asian",
                             "Latino",
                             "Black",
                             "Other race",
                             "Jewish",
                             "Catholic",
                             "Evangelical",
                             "Other or no religion",
                             "English second language",
                             "Aged 17 or less",
                             "Aged 19",
                             "Aged 20",
                             "Social science major",
                             "Humanities major",
                             "Science major",
                             "Business major",
                             "Attend to make money",
                             "Proportion high standardized test score",
                             "Proportion Asian",
                             "Proportion Latino ",
                             "Proportion other race ",
                             "Proportion Jewish ",
                             "Proportion Catholic ",
                             "Proportion Evangelical",
                             "Proportion other or no religion",
                             "Proportion English second languages ",
                             "Proportion aged 17 or less",
                             "Proportion aged 19",
                             "Proportion aged 20",
                             "Proportion social science major",
                             "Proportion humanities major",
                             "Proportion science major",
                             "Proportion business major",
                             "Proportion attending to make money",
                             "Mostly female",
                             "Mostly Black",
                             "Large student body",
                             "Public", 
                             "College",
                             "Northeast",
                             "South",
                             "1995",
                             "1996",
                             "1997",
                             "1998",
                             "1999",
                             "2000",
                             "2001",
                             "2002",
                             "2003",
                             "2004",
                             "2005",
                             "2006",
                             "2007",
                             "2008",
                             "2009",
                             "2010",
                             "2011",
                             "2012",
                             "2013",
                             "22-32 perc. affluent X moderator", 
                             "32-42 perc. affluent X moderator", 
                             "42-55 perc. affluent X moderator", 
                             "More than 55 perc. affluent X moderator", 
                             "Lagged DV",
                             "Lagged DV",
                             "Lagged DV",
                             "Lagged DV"))

texreg(list(passive.lis.critmass01, voting.lis.critmass01, campaign.lis.critmass01, protest.lis.critmass01, elected.lis.critmass01, orglead.lis.critmass01 ),
       caption = "The Effect of Campus Affluence on Financial Mechanism (Aggregate)", 
       custom.model.names = c("Passive Engagement", "Voting", "Campaigning", "Protesting", "Elected S.G.", "Leading Org."),
       caption.above = TRUE, digits = 3, stars = c(0.001, 0.01, 0.05))


texreg(list(passive.lis.emohealth_tfs_cohort01, voteprez2.lis.emohealth_tfs_cohort01, campaign.lis.emohealth_tfs_cohort01, protest.lis.emohealth_tfs_cohort01, elected.lis.emohealth_tfs_cohort01, orglead.lis.emohealth_tfs_cohort01 ),
       caption = "The Effect of Campus Affluence on Emotional Health (Aggregate)", 
       custom.model.names = c("Passive Engagement", "Voting", "Campaigning", "Protesting", "Elected S.G.", "Leading Org."),
       caption.above = TRUE, digits = 3, stars = c(0.001, 0.01, 0.05))

texreg(list(passive.lis.motivationlead_tfs_cohort01, voteprez2.lis.motivationlead_tfs_cohort01, campaign.lis.motivationlead_tfs_cohort01, protest.lis.motivationlead_tfs_cohort01, elected.lis.motivationlead_tfs_cohort01 ),
       caption = "The Effect of Campus Affluence on Motivation to Lead (Aggregate)", 
       custom.model.names = c("Passive Engagement", "Voting", "Campaigning", "Protesting", "Elected S.G."),
       caption.above = TRUE, digits = 3, stars = c(0.001, 0.01, 0.05))

#appendix - additional tests

cor(data.lis$affcat, data.lis$collaid_lis_ratio_cohrts_scld01, use = "complete.obs", method = "spearman")

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "passive_index_tfs_avg", 
               "passive_index_css_avg", "academcomp_tfs_cohort01")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$academcomp_tfs_cohort01 <- 0 
aff1.cat0 <- mean(predict(passive.lis.academcomp_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$academcomp_tfs_cohort01 <- 0 
aff5.cat0 <- mean(predict(passive.lis.academcomp_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

passive.academcomp_tfs01.cat0.agg.diff <- aff5.cat0 - aff1.cat0 
passive.academcomp_tfs01.cat0.agg.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$academcomp_tfs_cohort01 <- 1 
aff1.cat1 <- mean(predict(passive.lis.academcomp_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$academcomp_tfs_cohort01 <- 1 
aff5.cat1 <- mean(predict(passive.lis.academcomp_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

passive.academcomp_tfs01.cat1.agg.diff <- aff5.cat1 - aff1.cat1 
passive.academcomp_tfs01.cat1.agg.diff

###########
# Voting #
###########

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "academcomp_tfs_cohort01", 
               "voteprez2", "polaffairs_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$academcomp_tfs_cohort01 <- 0 
aff1.cat0 <- mean(predict(voteprez2.lis.academcomp_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$academcomp_tfs_cohort01 <- 0 
aff5.cat0 <- mean(predict(voteprez2.lis.academcomp_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

voting.academcomp_tfs01.cat0.agg.diff <- aff5.cat0 - aff1.cat0 
voting.academcomp_tfs01.cat0.agg.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$academcomp_tfs_cohort01 <- 1 
aff1.cat1 <- mean(predict(voteprez2.lis.academcomp_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$academcomp_tfs_cohort01 <- 1 
aff5.cat1 <- mean(predict(voteprez2.lis.academcomp_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

voting.academcomp_tfs01.cat1.agg.diff <- aff5.cat1 - aff1.cat1 
voting.academcomp_tfs01.cat1.agg.diff
###############
# Campaigning #
###############

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "academcomp_tfs_cohort01", 
               "campaign_css", "campaign_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$academcomp_tfs_cohort01 <- 0 
aff1.cat0 <- mean(predict(campaign.lis.academcomp_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$academcomp_tfs_cohort01 <- 0 
aff5.cat0 <- mean(predict(campaign.lis.academcomp_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

campaign.academcomp_tfs01.cat0.agg.diff <- aff5.cat0 - aff1.cat0 
campaign.academcomp_tfs01.cat0.agg.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$academcomp_tfs_cohort01 <- 1 
aff1.cat1 <- mean(predict(campaign.lis.academcomp_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$academcomp_tfs_cohort01 <- 1 
aff5.cat1 <- mean(predict(campaign.lis.academcomp_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

campaign.academcomp_tfs01.cat1.agg.diff <- aff5.cat1 - aff1.cat1 
campaign.academcomp_tfs01.cat1.agg.diff

###########
# Protest #
########### 

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "academcomp_tfs_cohort01", 
               "protestindex_css", "protest_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$academcomp_tfs_cohort01 <- 0 
aff1.cat0 <- mean(predict(protest.lis.academcomp_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$academcomp_tfs_cohort01 <- 0 
aff5.cat0 <- mean(predict(protest.lis.academcomp_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

protest.academcomp_tfs01.cat0.agg.diff <- aff5.cat0 - aff1.cat0
protest.academcomp_tfs01.cat0.agg.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$academcomp_tfs_cohort01 <- 1 
aff1.cat1 <- mean(predict(protest.lis.academcomp_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$academcomp_tfs_cohort01 <- 1 
aff5.cat1 <- mean(predict(protest.lis.academcomp_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

protest.academcomp_tfs01.cat1.agg.diff <- aff5.cat1 - aff1.cat1 
protest.academcomp_tfs01.cat1.agg.diff 

#############################
# Elected to Student Office #
############################

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "academcomp_tfs_cohort01", 
               "elected01_gov", "commlead_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$academcomp_tfs_cohort01 <- 0 
aff1.cat0 <- mean(predict(elected.lis.academcomp_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))


fixed <- data.lis.temp
fixed$affcat <- 5
fixed$academcomp_tfs_cohort01 <- 0 
aff5.cat0 <- mean(predict(elected.lis.academcomp_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

elected.academcomp_tfs01.cat0.agg.diff <- aff5.cat0 - aff1.cat0 
elected.academcomp_tfs01.cat0.agg.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$academcomp_tfs_cohort01 <- 1 
aff1.cat1 <- mean(predict(elected.lis.academcomp_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$academcomp_tfs_cohort01 <- 1 
aff5.cat1 <- mean(predict(elected.lis.academcomp_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

elected.academcomp_tfs01.cat1.agg.diff <- aff5.cat1 - aff1.cat1 
elected.academcomp_tfs01.cat1.agg.diff

#############################
# Lead Student Organization # 
#############################

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "academcomp_tfs_cohort01", 
               "orglead01", "commlead_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]
fixed <- data.lis.temp
fixed$affcat <- 1
fixed$academcomp_tfs_cohort01 <- 0 
aff1.cat0 <- mean(predict(orglead.lis.academcomp_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$academcomp_tfs_cohort01 <- 0 
aff5.cat0 <- mean(predict(orglead.lis.academcomp_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

orglead.academcomp_tfs01.cat0.agg.diff <- aff5.cat0 - aff1.cat0
orglead.academcomp_tfs01.cat0.agg.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$academcomp_tfs_cohort01 <- 1 
aff1.cat1 <- mean(predict(orglead.lis.academcomp_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))


fixed <- data.lis.temp
fixed$affcat <- 5
fixed$academcomp_tfs_cohort01 <- 1 
aff5.cat1 <- mean(predict(orglead.lis.academcomp_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

orglead.academcomp_tfs01.cat1.agg.diff <- aff5.cat1 - aff1.cat1
orglead.academcomp_tfs01.cat1.agg.diff


#########
# For Moderation table #
#########

list(passive.academcomp_tfs01.cat0.agg.diff, passive.academcomp_tfs01.cat1.agg.diff, (passive.academcomp_tfs01.cat1.agg.diff-passive.academcomp_tfs01.cat0.agg.diff) )
list(voting.academcomp_tfs01.cat0.agg.diff, voting.academcomp_tfs01.cat1.diff, (voting.academcomp_tfs01.cat1.agg.diff-voting.academcomp_tfs01.cat0.agg.diff) )
list(campaign.academcomp_tfs01.cat0.agg.diff, campaign.academcomp_tfs01.cat1.agg.diff, (campaign.academcomp_tfs01.cat1.agg.diff-campaign.academcomp_tfs01.cat0.agg.diff) )
list(protest.academcomp_tfs01.cat0.agg.diff, protest.academcomp_tfs01.cat1.agg.diff, (protest.academcomp_tfs01.cat1.agg.diff-protest.academcomp_tfs01.cat0.agg.diff) )
list(elected.academcomp_tfs01.cat0.agg.diff, elected.academcomp_tfs01.cat1.agg.diff, (elected.academcomp_tfs01.cat1.agg.diff-elected.academcomp_tfs01.cat0.agg.diff) )
list(orglead.academcomp_tfs01.cat0.agg.diff, orglead.academcomp_tfs01.cat1.agg.diff, (orglead.academcomp_tfs01.cat1.agg.diff-orglead.academcomp_tfs01.cat0.agg.diff) )






#now aggregate emotional health

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "passive_index_tfs_avg", 
               "passive_index_css_avg", "emohealth_tfs_cohort01")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$emohealth_tfs_cohort01 <- 0 
aff1.cat0 <- mean(predict(passive.lis.emohealth_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE), na.rm = T)

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$emohealth_tfs_cohort01 <- 0 
aff5.cat0 <- mean(predict(passive.lis.emohealth_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE), na.rm = T)

# Take difference

passive.emohealth_tfs.cat0.agg.diff <- aff5.cat0 - aff1.cat0 
passive.emohealth_tfs.cat0.agg.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$emohealth_tfs_cohort01 <- 1 
aff1.cat1 <- mean(predict(passive.lis.emohealth_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE), na.rm = T)

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$emohealth_tfs_cohort01 <- 1 
aff5.cat1 <- mean(predict(passive.lis.emohealth_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE), na.rm = T)

# Take difference

passive.emohealth_tfs.cat1.agg.diff <- aff5.cat1 - aff1.cat1 

passive.emohealth_tfs.cat1.agg.diff
###########
# Voting #
###########

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "emohealth_tfs_cohort01", 
               "voteprez2", "polaffairs_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$emohealth_tfs_cohort01 <- 0 
aff1.cat0 <- mean(predict(voteprez2.lis.emohealth_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$emohealth_tfs_cohort01 <- 0 
aff5.cat0 <- mean(predict(voteprez2.lis.emohealth_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

voting.emohealth_tfs.cat0.agg.diff <- aff5.cat0 - aff1.cat0 
voting.emohealth_tfs.cat0.agg.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$emohealth_tfs_cohort01 <- 1 
aff1.cat1 <- mean(predict(voteprez2.lis.emohealth_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$emohealth_tfs_cohort01 <- 1 
aff5.cat1 <- mean(predict(voteprez2.lis.emohealth_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

voting.emohealth_tfs.cat1.agg.diff <- aff5.cat1 - aff1.cat1 
voting.emohealth_tfs.cat1.agg.diff

###############
# Campaigning #
###############

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "emohealth_tfs_cohort01", 
               "campaign_css", "campaign_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$emohealth_tfs_cohort01 <- 0 
aff1.cat0 <- mean(predict(campaign.lis.emohealth_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$emohealth_tfs_cohort01 <- 0 
aff5.cat0 <- mean(predict(campaign.lis.emohealth_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

campaign.emohealth_tfs.cat0.agg.diff <- aff5.cat0 - aff1.cat0 
campaign.emohealth_tfs.cat0.agg.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$emohealth_tfs_cohort01 <- 1 
aff1.cat1 <- mean(predict(campaign.lis.emohealth_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$emohealth_tfs_cohort01 <- 1 
aff5.cat1 <- mean(predict(campaign.lis.emohealth_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

campaign.emohealth_tfs.cat1.agg.diff <- aff5.cat1 - aff1.cat1 
campaign.emohealth_tfs.cat1.agg.diff

###########
# Protest #
########### 

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "emohealth_tfs_cohort01", 
               "protestindex_css", "protest_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$emohealth_tfs_cohort01 <- 0 
aff1.cat0 <- mean(predict(protest.lis.emohealth_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$emohealth_tfs_cohort01 <- 0 
aff5.cat0 <- mean(predict(protest.lis.emohealth_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

protest.emohealth_tfs.cat0.agg.diff <- aff5.cat0 - aff1.cat0
protest.emohealth_tfs.cat0.agg.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$emohealth_tfs_cohort01 <- 1 
aff1.cat1 <- mean(predict(protest.lis.emohealth_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$emohealth_tfs_cohort01 <- 1 
aff5.cat1 <- mean(predict(protest.lis.emohealth_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

protest.emohealth_tfs.cat1.agg.diff <- aff5.cat1 - aff1.cat1 
protest.emohealth_tfs.cat1.agg.diff

#############################
# Elected to Student Office #
#############################

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "emohealth_tfs_cohort01", 
               "elected01_gov", "commlead_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$emohealth_tfs_cohort01 <- 0 
aff1.cat0 <- mean(predict(elected.lis.emohealth_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$emohealth_tfs_cohort01 <- 0 
aff5.cat0 <- mean(predict(elected.lis.emohealth_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

elected.emohealth_tfs.cat0.agg.diff <- aff5.cat0 - aff1.cat0 
elected.emohealth_tfs.cat0.agg.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$emohealth_tfs_cohort01 <- 1 
aff1.cat1 <- mean(predict(elected.lis.emohealth_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$emohealth_tfs_cohort01 <- 1 
aff5.cat1 <- mean(predict(elected.lis.emohealth_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

elected.emohealth_tfs.cat1.agg.diff <- aff5.cat1 - aff1.cat1 
elected.emohealth_tfs.cat1.agg.diff

#############################
# Lead Student Organization # 
#############################

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "emohealth_tfs_cohort01", 
               "orglead01", "commlead_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$emohealth_tfs_cohort01 <- 0 
aff1.cat0 <- mean(predict(orglead.lis.emohealth_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$emohealth_tfs_cohort01 <- 0 
aff5.cat0 <- mean(predict(orglead.lis.emohealth_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

orglead.emohealth_tfs.cat0.agg.diff <- aff5.cat0 - aff1.cat0
orglead.emohealth_tfs.cat0.agg.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$emohealth_tfs_cohort01 <- 1 
aff1.cat1 <- mean(predict(orglead.lis.emohealth_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$emohealth_tfs_cohort01 <- 1 
aff5.cat1 <- mean(predict(orglead.lis.emohealth_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

orglead.emohealth_tfs.cat1.agg.diff <- aff5.cat1 - aff1.cat1
orglead.emohealth_tfs.cat1.agg.diff
#########
# Table #
#########

list(passive.emohealth_tfs.cat0.agg.diff, passive.emohealth_tfs.cat1.agg.diff, (passive.emohealth_tfs.cat1.agg.diff-passive.emohealth_tfs.cat0.agg.diff) )
list(voting.emohealth_tfs.cat0.agg.diff, voting.emohealth_tfs.cat1.agg.diff, (voting.emohealth_tfs.cat1.agg.diff-voting.emohealth_tfs.cat0.agg.diff) )
list(campaign.emohealth_tfs.cat0.agg.diff, campaign.emohealth_tfs.cat1.agg.diff, (campaign.emohealth_tfs.cat1.agg.diff-campaign.emohealth_tfs.cat0.agg.diff) )
list(protest.emohealth_tfs.cat0.agg.diff, protest.emohealth_tfs.cat1.agg.diff, (protest.emohealth_tfs.cat1.agg.diff-protest.emohealth_tfs.cat0.agg.diff) )
list(elected.emohealth_tfs.cat0.agg.diff, elected.emohealth_tfs.cat1.agg.diff, (elected.emohealth_tfs.cat1.agg.diff-elected.emohealth_tfs.cat0.agg.diff) )
list(orglead.emohealth_tfs.cat0.agg.diff, orglead.emohealth_tfs.cat1.agg.diff, (orglead.emohealth_tfs.cat1.agg.diff-orglead.emohealth_tfs.cat0.agg.diff) )




#now aggregate motivational to lead

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "passive_index_tfs_avg", 
               "passive_index_css_avg", "motivationlead_tfs_cohort01")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$motivationlead_tfs_cohort01 <- 0 
aff1.cat0 <- mean(predict(passive.lis.motivationlead_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE), na.rm = T)

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$motivationlead_tfs_cohort01 <- 0 
aff5.cat0 <- mean(predict(passive.lis.motivationlead_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE), na.rm = T)

# Take difference

passive.motivationlead_tfs.cat0.agg.diff <- aff5.cat0 - aff1.cat0 
passive.motivationlead_tfs.cat0.agg.diff 

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$motivationlead_tfs_cohort01 <- 1 
aff1.cat1 <- mean(predict(passive.lis.motivationlead_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE), na.rm = T)

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$motivationlead_tfs_cohort01 <- 1 
aff5.cat1 <- mean(predict(passive.lis.motivationlead_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE), na.rm = T)

# Take difference

passive.motivationlead_tfs.cat1.agg.diff <- aff5.cat1 - aff1.cat1 
passive.motivationlead_tfs.cat1.agg.diff 
###########
# Voting #
###########

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "motivationlead_tfs_cohort01", 
               "voteprez2", "polaffairs_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$motivationlead_tfs_cohort01 <- 0 
aff1.cat0 <- mean(predict(voteprez2.lis.motivationlead_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$motivationlead_tfs_cohort01 <- 0 
aff5.cat0 <- mean(predict(voteprez2.lis.motivationlead_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

voting.motivationlead_tfs.cat0.agg.diff <- aff5.cat0 - aff1.cat0 
voting.motivationlead_tfs.cat0.agg.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$motivationlead_tfs_cohort01 <- 1 
aff1.cat1 <- mean(predict(voteprez2.lis.motivationlead_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$motivationlead_tfs_cohort01 <- 1 
aff5.cat1 <- mean(predict(voteprez2.lis.motivationlead_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

voting.motivationlead_tfs.cat1.agg.diff <- aff5.cat1 - aff1.cat1 
voting.motivationlead_tfs.cat1.agg.diff
###############
# Campaigning #
###############

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "motivationlead_tfs_cohort01", 
               "campaign_css", "campaign_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$motivationlead_tfs_cohort01 <- 0 
aff1.cat0 <- mean(predict(campaign.lis.motivationlead_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$motivationlead_tfs_cohort01 <- 0 
aff5.cat0 <- mean(predict(campaign.lis.motivationlead_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

campaign.motivationlead_tfs.cat0.agg.diff <- aff5.cat0 - aff1.cat0 
campaign.motivationlead_tfs.cat0.agg.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$motivationlead_tfs_cohort01 <- 1 
aff1.cat1 <- mean(predict(campaign.lis.motivationlead_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$motivationlead_tfs_cohort01 <- 1 
aff5.cat1 <- mean(predict(campaign.lis.motivationlead_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

campaign.motivationlead_tfs.cat1.agg.diff <- aff5.cat1 - aff1.cat1 
campaign.motivationlead_tfs.cat1.agg.diff
###########
# Protest #
########### 

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "motivationlead_tfs_cohort01", 
               "protestindex_css", "protest_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$motivationlead_tfs_cohort01 <- 0 
aff1.cat0 <- mean(predict(protest.lis.motivationlead_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$motivationlead_tfs_cohort01 <- 0 
aff5.cat0 <- mean(predict(protest.lis.motivationlead_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

protest.motivationlead_tfs.cat0.agg.diff <- aff5.cat0 - aff1.cat0
protest.motivationlead_tfs.cat0.agg.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$motivationlead_tfs_cohort01 <- 1 
aff1.cat1 <- mean(predict(protest.lis.motivationlead_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$motivationlead_tfs_cohort01 <- 1 
aff5.cat1 <- mean(predict(protest.lis.motivationlead_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

protest.motivationlead_tfs.cat1.agg.diff <- aff5.cat1 - aff1.cat1 
protest.motivationlead_tfs.cat1.agg.diff

#############################
# Elected to Student Office #
#############################

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "motivationlead_tfs_cohort01", 
               "elected01_gov", "commlead_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$motivationlead_tfs_cohort01 <- 0 
aff1.cat0 <- mean(predict(elected.lis.motivationlead_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$motivationlead_tfs_cohort01 <- 0 
aff5.cat0 <- mean(predict(elected.lis.motivationlead_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

elected.motivationlead_tfs.cat0.agg.diff <- aff5.cat0 - aff1.cat0 
elected.motivationlead_tfs.cat0.agg.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$motivationlead_tfs_cohort01 <- 1 
aff1.cat1 <- mean(predict(elected.lis.motivationlead_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$motivationlead_tfs_cohort01 <- 1 
aff5.cat1 <- mean(predict(elected.lis.motivationlead_tfs_cohort01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

elected.motivationlead_tfs.cat1.agg.diff <- aff5.cat1 - aff1.cat1 
elected.motivationlead_tfs.cat1.agg.diff


#########
# Table #
#########

list(passive.motivationlead_tfs.cat0.agg.diff, passive.motivationlead_tfs.cat1.agg.diff, (passive.motivationlead_tfs.cat1.agg.diff-passive.motivationlead_tfs.cat0.agg.diff) )
list(voting.motivationlead_tfs.cat0.agg.diff, voting.motivationlead_tfs.cat1.agg.diff, (voting.motivationlead_tfs.cat1.agg.diff-voting.motivationlead_tfs.cat0.agg.diff) )
list(campaign.motivationlead_tfs.cat0.agg.diff, campaign.motivationlead_tfs.cat1.agg.diff, (campaign.motivationlead_tfs.cat1.agg.diff-campaign.motivationlead_tfs.cat0.agg.diff) )
list(protest.motivationlead_tfs.cat0.agg.diff, protest.motivationlead_tfs.cat1.agg.diff, (protest.motivationlead_tfs.cat1.agg.diff-protest.motivationlead_tfs.cat0.agg.diff) )
list(elected.motivationlead_tfs.cat0.agg.diff, elected.motivationlead_tfs.cat1.agg.diff, (elected.motivationlead_tfs.cat1.agg.diff-elected.motivationlead_tfs.cat0.agg.diff) )





# Aggregate Financial Aid #

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "collaidratio_lis_school01", 
               "passive_index_css_avg", "passive_index_tfs_avg")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$collaidratio_lis_school01 <- 0 
aff1.cat0 <- mean(predict(passive.lis.collaidratio.lis.school01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$collaidratio_lis_school01 <- 0 
aff5.cat0 <- mean(predict(passive.lis.collaidratio.lis.school01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

passive.collaidratio.lis.school01.cat0.diff <- aff5.cat0 - aff1.cat0 
passive.collaidratio.lis.school01.cat0.diff 

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$collaidratio_lis_school01 <- 1 
aff1.cat1 <- mean(predict(passive.lis.collaidratio.lis.school01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$collaidratio_lis_school01 <- 1 
aff5.cat1 <- mean(predict(passive.lis.collaidratio.lis.school01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

passive.collaidratio.lis.school01.cat1.diff <- aff5.cat1 - aff1.cat1 
passive.collaidratio.lis.school01.cat1.diff 

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "collaidratio_lis_school01", 
               "voteprez2", "polaffairs_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$collaidratio_lis_school01 <- 0 
aff1.cat0 <- mean(predict(voting.lis.collaidratio.lis.school01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$collaidratio_lis_school01 <- 0 
aff5.cat0 <- mean(predict(voting.lis.collaidratio.lis.school01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

voting.collaidratio.lis.school01.cat0.diff <- aff5.cat0 - aff1.cat0 
voting.collaidratio.lis.school01.cat0.diff 

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$collaidratio_lis_school01 <- 1 
aff1.cat1 <- mean(predict(voting.lis.collaidratio.lis.school01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$collaidratio_lis_school01 <- 1 
aff5.cat1 <- mean(predict(voting.lis.collaidratio.lis.school01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

voting.collaidratio.lis.school01.cat1.diff <- aff5.cat1 - aff1.cat1 
voting.collaidratio.lis.school01.cat1.diff

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "collaidratio_lis_school01", 
               "campaign_css", "campaign_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$collaidratio_lis_school01 <- 0 
aff1.cat0 <- mean(predict(campaign.lis.collaidratio.lis.school01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$collaidratio_lis_school01 <- 0 
aff5.cat0 <- mean(predict(campaign.lis.collaidratio.lis.school01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

campaign.collaidratio.lis.school01.cat0.diff <- aff5.cat0 - aff1.cat0 
campaign.collaidratio.lis.school01.cat0.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$collaidratio_lis_school01 <- 1 
aff1.cat1 <- mean(predict(campaign.lis.collaidratio.lis.school01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$collaidratio_lis_school01 <- 1 
aff5.cat1 <- mean(predict(campaign.lis.collaidratio.lis.school01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

campaign.collaidratio.lis.school01.cat1.diff <- aff5.cat1 - aff1.cat1 
campaign.collaidratio.lis.school01.cat1.diff

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "collaidratio_lis_school01", 
               "protestindex_css", "protest_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$collaidratio_lis_school01 <- 0 
aff1.cat0 <- mean(predict(protest.lis.collaidratio.lis.school01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$collaidratio_lis_school01 <- 0 
aff5.cat0 <- mean(predict(protest.lis.collaidratio.lis.school01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

protest.collaidratio.lis.school01.cat0.diff <- aff5.cat0 - aff1.cat0
protest.collaidratio.lis.school01.cat0.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$collaidratio_lis_school01 <- 1 
aff1.cat1 <- mean(predict(protest.lis.collaidratio.lis.school01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$collaidratio_lis_school01 <- 1 
aff5.cat1 <- mean(predict(protest.lis.collaidratio.lis.school01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

protest.collaidratio.lis.school01.cat1.diff <- aff5.cat1 - aff1.cat1 
protest.collaidratio.lis.school01.cat1.diff

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "collaidratio_lis_school01", 
               "elected01_gov", "commlead_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$collaidratio_lis_school01 <- 0 
aff1.cat0 <- mean(predict(elected.lis.collaidratio.lis.school01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$collaidratio_lis_school01 <- 0 
aff5.cat0 <- mean(predict(elected.lis.collaidratio.lis.school01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

elected.collaidratio.lis.school01.cat0.diff <- aff5.cat0 - aff1.cat0 
elected.collaidratio.lis.school01.cat0.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$collaidratio_lis_school01 <- 1 
aff1.cat1 <- mean(predict(elected.lis.collaidratio.lis.school01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$collaidratio_lis_school01 <- 1 
aff5.cat1 <- mean(predict(elected.lis.collaidratio.lis.school01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

elected.collaidratio.lis.school01.cat1.diff <- aff5.cat1 - aff1.cat1 
elected.collaidratio.lis.school01.cat1.diff

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "collaidratio_lis_school01", 
               "orglead01", "commlead_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$collaidratio_lis_school01 <- 0 
aff1.cat0 <- mean(predict(orglead.lis.collaidratio.lis.school01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$collaidratio_lis_school01 <- 0 
aff5.cat0 <- mean(predict(orglead.lis.collaidratio.lis.school01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

orglead.collaidratio.lis.school01.cat0.diff <- aff5.cat0 - aff1.cat0
orglead.collaidratio.lis.school01.cat0.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$collaidratio_lis_school01 <- 1 
aff1.cat1 <- mean(predict(orglead.lis.collaidratio.lis.school01, fixed, type = "response", allow.new.levels=TRUE))


fixed <- data.lis.temp
fixed$affcat <- 5
fixed$collaidratio_lis_school01 <- 1 
aff5.cat1 <- mean(predict(orglead.lis.collaidratio.lis.school01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

orglead.collaidratio.lis.school01.cat1.diff <- aff5.cat1 - aff1.cat1
orglead.collaidratio.lis.school01.cat1.diff

############
## for table
############

list(passive.collaidratio.lis.school01.cat0.diff, passive.collaidratio.lis.school01.cat1.diff, (passive.collaidratio.lis.school01.cat1.diff-passive.collaidratio.lis.school01.cat0.diff) )
list(voting.collaidratio.lis.school01.cat0.diff, voting.collaidratio.lis.school01.cat1.diff, (voting.collaidratio.lis.school01.cat1.diff-voting.collaidratio.lis.school01.cat0.diff) )
list(campaign.collaidratio.lis.school01.cat0.diff, campaign.collaidratio.lis.school01.cat1.diff, (campaign.collaidratio.lis.school01.cat1.diff-campaign.collaidratio.lis.school01.cat0.diff) )
list(protest.collaidratio.lis.school01.cat0.diff, protest.collaidratio.lis.school01.cat1.diff, (protest.collaidratio.lis.school01.cat1.diff-protest.collaidratio.lis.school01.cat0.diff) )
list(elected.collaidratio.lis.school01.cat0.diff, elected.collaidratio.lis.school01.cat1.diff, (elected.collaidratio.lis.school01.cat1.diff-elected.collaidratio.lis.school01.cat0.diff) )
list(orglead.collaidratio.lis.school01.cat0.diff, orglead.collaidratio.lis.school01.cat1.diff, (orglead.collaidratio.lis.school01.cat1.diff-orglead.collaidratio.lis.school01.cat0.diff) )



# Aggregate Percent LIS/Pell #

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "critmass01", 
               "passive_index_css_avg", "passive_index_tfs_avg")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$critmass01 <- 0 
aff1.cat0 <- mean(predict(passive.lis.critmass01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$critmass01 <- 0 
aff5.cat0 <- mean(predict(passive.lis.critmass01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

passive.critmass01.cat0.diff <- aff5.cat0 - aff1.cat0 
passive.critmass01.cat0.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$critmass01 <- 1 
aff1.cat1 <- mean(predict(passive.lis.critmass01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$critmass01 <- 1 
aff5.cat1 <- mean(predict(passive.lis.critmass01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

passive.critmass01.cat1.diff <- aff5.cat1 - aff1.cat1 
passive.critmass01.cat1.diff

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "critmass01", 
               "voteprez2", "polaffairs_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$critmass01 <- 0 
aff1.cat0 <- mean(predict(voting.lis.critmass01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$critmass01 <- 0 
aff5.cat0 <- mean(predict(voting.lis.critmass01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

voting.critmass01.cat0.diff <- aff5.cat0 - aff1.cat0 
voting.critmass01.cat0.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$critmass01 <- 1 
aff1.cat1 <- mean(predict(voting.lis.critmass01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$critmass01 <- 1 
aff5.cat1 <- mean(predict(voting.lis.critmass01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

voting.critmass01.cat1.diff <- aff5.cat1 - aff1.cat1 

voting.critmass01.cat1.diff

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "critmass01", 
               "campaign_css", "campaign_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$critmass01 <- 0 
aff1.cat0 <- mean(predict(campaign.lis.critmass01, fixed, type = "response", allow.new.levels=TRUE))


fixed <- data.lis.temp
fixed$affcat <- 5
fixed$critmass01 <- 0 
aff5.cat0 <- mean(predict(campaign.lis.critmass01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

campaign.critmass01.cat0.diff <- aff5.cat0 - aff1.cat0 
campaign.critmass01.cat0.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$critmass01 <- 1 
aff1.cat1 <- mean(predict(campaign.lis.critmass01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$critmass01 <- 1 
aff5.cat1 <- mean(predict(campaign.lis.critmass01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

campaign.critmass01.cat1.diff <- aff5.cat1 - aff1.cat1 
campaign.critmass01.cat1.diff

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "critmass01", 
               "protestindex_css", "protest_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$critmass01 <- 0 
aff1.cat0 <- mean(predict(protest.lis.critmass01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$critmass01 <- 0 
aff5.cat0 <- mean(predict(protest.lis.critmass01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

protest.critmass01.cat0.diff <- aff5.cat0 - aff1.cat0
protest.critmass01.cat0.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$critmass01 <- 1 
aff1.cat1 <- mean(predict(protest.lis.critmass01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$critmass01 <- 1 
aff5.cat1 <- mean(predict(protest.lis.critmass01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

protest.critmass01.cat1.diff <- aff5.cat1 - aff1.cat1 
protest.critmass01.cat1.diff 

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "critmass01", 
               "elected01_gov", "commlead_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$critmass01 <- 0 
aff1.cat0 <- mean(predict(elected.lis.critmass01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$critmass01 <- 0 
aff5.cat0 <- mean(predict(elected.lis.critmass01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

elected.critmass01.cat0.diff <- aff5.cat0 - aff1.cat0 
elected.critmass01.cat0.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$critmass01 <- 1 
aff1.cat1 <- mean(predict(elected.lis.critmass01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$critmass01 <- 1 
aff5.cat1 <- mean(predict(elected.lis.critmass01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

elected.critmass01.cat1.diff <- aff5.cat1 - aff1.cat1 
elected.critmass01.cat1.diff 

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "critmass01", 
               "orglead01", "commlead_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$critmass01 <- 0 
aff1.cat0 <- mean(predict(orglead.lis.critmass01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$critmass01 <- 0 
aff5.cat0 <- mean(predict(orglead.lis.critmass01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

orglead.critmass01.cat0.diff <- aff5.cat0 - aff1.cat0
orglead.critmass01.cat0.diff

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$critmass01 <- 1 
aff1.cat1 <- mean(predict(orglead.lis.critmass01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$critmass01 <- 1 
aff5.cat1 <- mean(predict(orglead.lis.critmass01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

orglead.critmass01.cat1.diff <- aff5.cat1 - aff1.cat1
orglead.critmass01.cat1.diff
############
## for table
############

list(passive.critmass01.cat0.diff, passive.critmass01.cat1.diff, (passive.critmass01.cat1.diff-passive.critmass01.cat0.diff) )
list(voting.critmass01.cat0.diff, voting.critmass01.cat1.diff, (voting.critmass01.cat1.diff-voting.critmass01.cat0.diff) )
list(campaign.critmass01.cat0.diff, campaign.critmass01.cat1.diff, (campaign.critmass01.cat1.diff-campaign.critmass01.cat0.diff) )
list(protest.critmass01.cat0.diff, protest.critmass01.cat1.diff, (protest.critmass01.cat1.diff-protest.critmass01.cat0.diff) )
list(elected.critmass01.cat0.diff, elected.critmass01.cat1.diff, (elected.critmass01.cat1.diff-elected.critmass01.cat0.diff) )
list(orglead.critmass01.cat0.diff, orglead.critmass01.cat1.diff, (orglead.critmass01.cat1.diff-orglead.critmass01.cat0.diff) )

#loan amount, school-level


modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "passive_index_tfs_avg", 
               "passive_index_css_avg", "loanamt_ratio_scaled01")

data.lis <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$loanamt_ratio_scaled01 <- 0 
aff1.cat0 <- mean(predict(passive.lis.loanamt.ratio.scaled01 , fixed, type = "response", allow.new.levels=TRUE), na.rm = T)

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$loanamt_ratio_scaled01 <- 0 
aff5.cat0 <- mean(predict(passive.lis.loanamt.ratio.scaled01 , fixed, type = "response", allow.new.levels=TRUE), na.rm = T)

# Take difference

passive.loanamt.ratio.scaled01.cat0.diff <- aff5.cat0 - aff1.cat0 
passive.loanamt.ratio.scaled01.cat0.diff


fixed <- data.lis.temp
fixed$affcat <- 1
fixed$loanamt_ratio_scaled01 <- 1 
aff1.cat1 <- mean(predict(passive.lis.loanamt.ratio.scaled01, fixed, type = "response", allow.new.levels=TRUE), na.rm = T)

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$loanamt_ratio_scaled01 <- 1 
aff5.cat1 <- mean(predict(passive.lis.loanamt.ratio.scaled01, fixed, type = "response", allow.new.levels=TRUE), na.rm = T)

# Take difference

passive.loanamt.ratio.scaled01.cat1.diff <- aff5.cat1 - aff1.cat1 
passive.loanamt.ratio.scaled01.cat1.diff

###########
# Voting #
###########

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "loanamt_ratio_scaled01", 
               "voteprez2", "polaffairs_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$loanamt_ratio_scaled01 <- 0 
aff1.cat0 <- mean(predict(voteprez2.lis.loanamt.ratio.scaled01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$loanamt_ratio_scaled01 <- 0 
aff5.cat0 <- mean(predict(voteprez2.lis.loanamt.ratio.scaled01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

voting.loanamt.ratio.scaled01.cat0.diff <- aff5.cat0 - aff1.cat0 
voting.loanamt.ratio.scaled01.cat0.diff


fixed <- data.lis.temp
fixed$affcat <- 1
fixed$loanamt_ratio_scaled01 <- 1 
aff1.cat1 <- mean(predict(voteprez2.lis.loanamt.ratio.scaled01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$loanamt_ratio_scaled01 <- 1 
aff5.cat1 <- mean(predict(voteprez2.lis.loanamt.ratio.scaled01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

voting.loanamt.ratio.scaled01.cat1.diff <- aff5.cat1 - aff1.cat1 
voting.loanamt.ratio.scaled01.cat1.diff


###############
# Campaigning #
###############

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "loanamt_ratio_scaled01", 
               "campaign_css", "campaign_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$loanamt_ratio_scaled01 <- 0 
aff1.cat0 <- mean(predict(campaign.lis.loanamt.ratio.scaled01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$loanamt_ratio_scaled01 <- 0 
aff5.cat0 <- mean(predict(campaign.lis.loanamt.ratio.scaled01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

campaign.loanamt.ratio.scaled01.cat0.diff <- aff5.cat0 - aff1.cat0 
campaign.loanamt.ratio.scaled01.cat0.diff


fixed <- data.lis.temp
fixed$affcat <- 1
fixed$loanamt_ratio_scaled01 <- 1 
aff1.cat1 <- mean(predict(campaign.lis.loanamt.ratio.scaled01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$loanamt_ratio_scaled01 <- 1 
aff5.cat1 <- mean(predict(campaign.lis.loanamt.ratio.scaled01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

campaign.loanamt.ratio.scaled01.cat1.diff <- aff5.cat1 - aff1.cat1 
campaign.loanamt.ratio.scaled01.cat1.diff


###########
# Protest #
########### 

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "loanamt_ratio_scaled01", 
               "protestindex_css", "protest_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$loanamt_ratio_scaled01 <- 0 
aff1.cat0 <- mean(predict(protest.lis.loanamt.ratio.scaled01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$loanamt_ratio_scaled01 <- 0 
aff5.cat0 <- mean(predict(protest.lis.loanamt.ratio.scaled01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

protest.loanamt.ratio.scaled01.cat0.diff <- aff5.cat0 - aff1.cat0
protest.loanamt.ratio.scaled01.cat0.diff


fixed <- data.lis.temp
fixed$affcat <- 1
fixed$loanamt_ratio_scaled01 <- 1 
aff1.cat1 <- mean(predict(protest.lis.loanamt.ratio.scaled01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$loanamt_ratio_scaled01 <- 1 
aff5.cat1 <- mean(predict(protest.lis.loanamt.ratio.scaled01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

protest.loanamt.ratio.scaled01.cat1.diff <- aff5.cat1 - aff1.cat1 
protest.loanamt.ratio.scaled01.cat1.diff


#############################
# Elected to Student Office #
#############################

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "loanamt_ratio_scaled01", 
               "elected01_gov", "commlead_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$loanamt_ratio_scaled01 <- 0 
aff1.cat0 <- mean(predict(elected.lis.loanamt.ratio.scaled01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$loanamt_ratio_scaled01 <- 0 
aff5.cat0 <- mean(predict(elected.lis.loanamt.ratio.scaled01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

elected.loanamt.ratio.scaled01.cat0.diff <- aff5.cat0 - aff1.cat0 
elected.loanamt.ratio.scaled01.cat0.diff


fixed <- data.lis.temp
fixed$affcat <- 1
fixed$loanamt_ratio_scaled01 <- 1 
aff1.cat1 <- mean(predict(elected.lis.loanamt.ratio.scaled01, fixed, type = "response", allow.new.levels=TRUE))

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$loanamt_ratio_scaled01 <- 1 
aff5.cat1 <- mean(predict(elected.lis.loanamt.ratio.scaled01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

elected.loanamt.ratio.scaled01.cat1.diff <- aff5.cat1 - aff1.cat1 
elected.loanamt.ratio.scaled01.cat1.diff


#############################
# Lead Student Organization # 
#############################

modelvars <- c("affcat", "hitestscore", "testscore_na", "female", "asian", "hispanic", "black",  "othrace",
               "jewish", "catholic", "evangelical", "otherornorelig", "notenglishfirst", "age17orless", "age19",
               "age20", "socscitfs", "humantfs", "sciencetfs", "businesstfs",  "makemoneyvimp",  "hitestscoreper",
               "hiasianper", "hihispanicper", "hiothraceper", "hijewishper", "hicatholicper", "hievangelicalper",
               "hiotherornoreligper", "notenglishfirstper", "age17orlessper", "age19per", "age20per", "socscitfsper",
               "humantfsper", "sciencetfsper", "businesstfsper", "makemoneyvimpper", "mostlyfemale", "mostlyblack",
               "largesb", "public", "college", "neast", "south","YEAR", "ACERECODE", "ace_year", "loanamt_ratio_scaled01", 
               "orglead01", "commlead_tfs")

data.lis.temp <- data.lis[complete.cases(data.lis[,modelvars]),]

fixed <- data.lis.temp
fixed$affcat <- 1
fixed$loanamt_ratio_scaled01 <- 0 
aff1.cat0 <- mean(predict(orglead.lis.loanamt.ratio.scaled01, fixed, type = "response", allow.new.levels=TRUE))
aff1.cat0

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$loanamt_ratio_scaled01 <- 0 
aff5.cat0 <- mean(predict(orglead.lis.loanamt.ratio.scaled01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

orglead.loanamt.ratio.scaled01.cat0.diff <- aff5.cat0 - aff1.cat0
orglead.loanamt.ratio.scaled01.cat0.diff


fixed <- data.lis.temp
fixed$affcat <- 1
fixed$loanamt_ratio_scaled01 <- 1 
aff1.cat1 <- mean(predict(orglead.lis.loanamt.ratio.scaled01, fixed, type = "response", allow.new.levels=TRUE))
aff1.cat1

fixed <- data.lis.temp
fixed$affcat <- 5
fixed$loanamt_ratio_scaled01 <- 1 
aff5.cat1 <- mean(predict(orglead.lis.loanamt.ratio.scaled01, fixed, type = "response", allow.new.levels=TRUE))

# Take difference

orglead.loanamt.ratio.scaled01.cat1.diff <- aff5.cat1 - aff1.cat1
orglead.loanamt.ratio.scaled01.cat1.diff


#########
# For Moderation table - individual level effects#
#########

list(passive.loanamt.ratio.scaled01.cat0.diff, passive.loanamt.ratio.scaled01.cat1.diff, (passive.loanamt.ratio.scaled01.cat1.diff-passive.loanamt.ratio.scaled01.cat0.diff) )
list(voting.loanamt.ratio.scaled01.cat0.diff, voting.loanamt.ratio.scaled01.cat1.diff, (voting.loanamt.ratio.scaled01.cat1.diff-voting.loanamt.ratio.scaled01.cat0.diff) )
list(campaign.loanamt.ratio.scaled01.cat0.diff, campaign.loanamt.ratio.scaled01.cat1.diff, (campaign.loanamt.ratio.scaled01.cat1.diff-campaign.loanamt.ratio.scaled01.cat0.diff) )
list(protest.loanamt.ratio.scaled01.cat0.diff, protest.loanamt.ratio.scaled01.cat1.diff, (protest.loanamt.ratio.scaled01.cat1.diff-protest.loanamt.ratio.scaled01.cat0.diff) )
list(elected.loanamt.ratio.scaled01.cat0.diff, elected.loanamt.ratio.scaled01.cat1.diff, (elected.loanamt.ratio.scaled01.cat1.diff-elected.loanamt.ratio.scaled01.cat0.diff) )
list(orglead.loanamt.ratio.scaled01.cat0.diff, orglead.loanamt.ratio.scaled01.cat1.diff, (orglead.loanamt.ratio.scaled01.cat1.diff-orglead.loanamt.ratio.scaled01.cat0.diff) )











###################
## Mediation models 
###################

#######################
# Political Mechanism #
#######################

##############
# Passive DV #
##############

# Mediator Models, regressing mediator on school affluence and controls

med.passive.lis.passive_tfs_cohort.DV  <- lmer(passive_tfs_cohort ~ medtreat + passive_index_tfs_avg + 
                                                 hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                                                 evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                 humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                                 hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                                                 notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                                                 businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                                                 south + factor(YEAR) + (1 | ACERECODE), data = data.lis[!is.na(data.lis$passive_index_css_avg),])

med.passive.mis.passive_tfs_cohort.DV  <- lmer(passive_tfs_cohort ~ medtreat + passive_index_tfs_avg + 
                                                 hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                                                 evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                 humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                                 hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                                                 notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                                                 businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                                                 south + factor(YEAR) + (1 | ACERECODE), data = data.mis.r[!is.na(data.mis.r$passive_index_css_avg),])

med.passive.his.passive_tfs_cohort.DV  <- lmer(passive_tfs_cohort ~ medtreat + passive_index_tfs_avg + 
                                                 hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                                                 evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                 humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                                 hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                                                 notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                                                 businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                                                 south + factor(YEAR) + (1 | ACERECODE), data = data.his.r[!is.na(data.his.r$passive_index_css_avg),])

# Outcome Models, regressing outcome on mediator, school affluence, and controls

med.passive.lis.passive_tfs_cohort.stand  <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + passive_tfs_cohort + medtreat +
                                                    hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                                                    evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                    humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                                    hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                                                    notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                                                    businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                                                    south + factor(YEAR) + (1 | ACERECODE), data = data.lis)

med.passive.mis.passive_tfs_cohort.stand  <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + passive_tfs_cohort + medtreat +
                                                    hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                                                    evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                    humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                                    hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                                                    notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                                                    businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                                                    south + factor(YEAR) + (1 | ACERECODE), data = data.mis.r)

med.passive.his.passive_tfs_cohort.stand  <- lmer(passive_index_css_avg ~ passive_index_tfs_avg + passive_tfs_cohort + medtreat +
                                                    hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                                                    evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                    humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                                    hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                                                    notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                                                    businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                                                    south + factor(YEAR) + (1 | ACERECODE), data = data.his.r)

## Run Mediation summary (exact numbers may vary due to simulations)

med.passive.passive_tfs_cohort.lis <- mediate(model.m = med.passive.lis.passive_tfs_cohort.DV, model.y = med.passive.lis.passive_tfs_cohort.stand, treat = "medtreat", 
                                              mediator = "passive_tfs_cohort", sims = 500 )
summary(med.passive.passive_tfs_cohort.lis)

med.passive.passive_tfs_cohort.mis <- mediate(model.m = med.passive.mis.passive_tfs_cohort.DV, model.y = med.passive.mis.passive_tfs_cohort.stand, treat = "medtreat", 
                                              mediator = "passive_tfs_cohort", sims = 500 )
summary(med.passive.passive_tfs_cohort.mis)

med.passive.passive_tfs_cohort.his <- mediate(model.m = med.passive.his.passive_tfs_cohort.DV, model.y = med.passive.his.passive_tfs_cohort.stand, treat = "medtreat", 
                                              mediator = "passive_tfs_cohort", sims = 500 )
summary(med.passive.passive_tfs_cohort.his)

##########
# Voting #
##########

## Mediator Models, regressing mediator on school affluence and controls

med.voteprez2.lis.passive_tfs_cohort.DV  <- lmer(passive_tfs_cohort ~ medtreat + polaffairs_tfs + 
                                                   hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                                                   evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                   humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                                   hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                                                   notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                                                   businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                                                   south + factor(YEAR) + (1 | ACERECODE), data = data.lis[!is.na(data.lis$voteprez2),])

med.voteprez2.mis.passive_tfs_cohort.DV  <- lmer(passive_tfs_cohort ~ medtreat + polaffairs_tfs + 
                                                   hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                                                   evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                   humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                                   hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                                                   notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                                                   businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                                                   south + factor(YEAR) + (1 | ACERECODE), data = data.mis.r[!is.na(data.mis.r$voteprez2),])

med.voteprez2.his.passive_tfs_cohort.DV  <- lmer(passive_tfs_cohort ~ medtreat + polaffairs_tfs + 
                                                   hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                                                   evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                   humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                                   hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                                                   notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                                                   businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                                                   south + factor(YEAR) + (1 | ACERECODE), data = data.his.r[!is.na(data.his.r$voteprez2),])

## Outcome Models, regressing outcome on mediator, school affluence, and controls

med.voteprez2.lis.passive_tfs_cohort.stand  <- glmer(voteprez2 ~ polaffairs_tfs + passive_tfs_cohort + medtreat +
                                                       polaffairs_tfs +  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                                                       catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                       humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                                                       hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                                                       age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                                                       makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                                                       (1 | ACERECODE), family = binomial("logit"),control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                                                     data = data.lis)


med.voteprez2.mis.passive_tfs_cohort.stand  <- glmer(voteprez2 ~ polaffairs_tfs + passive_tfs_cohort + medtreat +
                                                       polaffairs_tfs +  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                                                       catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                       humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                                                       hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                                                       age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                                                       makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                                                       (1 | ACERECODE), family = binomial("logit"),control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                                                     data = data.mis.r)

med.voteprez2.his.passive_tfs_cohort.stand  <- glmer(voteprez2 ~ polaffairs_tfs + passive_tfs_cohort + medtreat +
                                                       polaffairs_tfs +  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                                                       catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                       humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                                                       hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                                                       age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                                                       makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                                                       (1 | ACERECODE), family = binomial("logit"),control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                                                     data = data.his.r)

## Run Mediation summary (exact numbers may vary due to simulations)
med.voteprez2.passive_tfs_cohort.lis <- mediate(model.m = med.voteprez2.lis.passive_tfs_cohort.DV, model.y = med.voteprez2.lis.passive_tfs_cohort.stand, treat = "medtreat", 
                                                mediator = "passive_tfs_cohort", sims = 500 )
summary(med.voteprez2.passive_tfs_cohort.lis)

med.voteprez2.passive_tfs_cohort.mis <- mediate(model.m = med.voteprez2.mis.passive_tfs_cohort.DV, model.y = med.voteprez2.mis.passive_tfs_cohort.stand, treat = "medtreat", 
                                                mediator = "passive_tfs_cohort", sims = 500 )
summary(med.voteprez2.passive_tfs_cohort.mis)

med.voteprez2.passive_tfs_cohort.his <- mediate(model.m = med.voteprez2.his.passive_tfs_cohort.DV, model.y = med.voteprez2.his.passive_tfs_cohort.stand, treat = "medtreat", 
                                                mediator = "passive_tfs_cohort", sims = 500 )
summary(med.voteprez2.passive_tfs_cohort.his)

##############
# Protesting #
##############

## Mediator Models, regressing mediator on school affluence and controls

med.protest.lis.passive_tfs_cohort.DV  <- lmer(passive_tfs_cohort ~ medtreat + protest_tfs + 
                                                 hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                                                 catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                 humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                                                 hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                                                 age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                                                 makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                                                 (1 | ACERECODE), data = data.lis[!is.na(data.lis$protestindex_css),])

med.protest.mis.passive_tfs_cohort.DV  <- lmer(passive_tfs_cohort ~ medtreat + protest_tfs + 
                                                 hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                                                 catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                 humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                                                 hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                                                 age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                                                 makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                                                 (1 | ACERECODE), data = data.mis.r[!is.na(data.mis.r$protestindex_css),])

nobs(med.protest.mis.passive_tfs_cohort.DV)

med.protest.his.passive_tfs_cohort.DV  <- lmer(passive_tfs_cohort ~ medtreat + protest_tfs + 
                                                 hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                                                 catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                 humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                                                 hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                                                 age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                                                 makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                                                 (1 | ACERECODE), data = data.his.r[!is.na(data.his.r$protestindex_css),])

## Outcome Models, regressing outcome on mediator, school affluence, and controls

med.protest.lis.passive_tfs_cohort.stand  <- glmer(protestindex_css ~ protest_tfs + passive_tfs_cohort + medtreat +
                                                     hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                                                     catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                     humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                                                     hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                                                     age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                                                     makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                                                     (1 | ACERECODE),family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                                                   data = data.lis)

med.protest.mis.passive_tfs_cohort.stand  <- glmer(protestindex_css ~ protest_tfs + passive_tfs_cohort + medtreat +
                                                     hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                                                     catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                     humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                                                     hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                                                     age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                                                     makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                                                     (1 | ACERECODE),family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                                                   data = data.mis.r)

nobs(med.protest.mis.passive_tfs_cohort.stand)

med.protest.his.passive_tfs_cohort.stand  <- glmer(protestindex_css ~ protest_tfs + passive_tfs_cohort + medtreat +
                                                     hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                                                     catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                     humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                                                     hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                                                     age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                                                     makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                                                     (1 | ACERECODE),family = binomial("logit"), control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                                                   data = data.his.r)

## Run Mediation summary (exact numbers may vary due to simulations)
med.protest.passive_tfs_cohort.lis <- mediate(model.m = med.protest.lis.passive_tfs_cohort.DV, model.y = med.protest.lis.passive_tfs_cohort.stand, treat = "medtreat", 
                                              mediator = "passive_tfs_cohort", sims = 500 )
summary(med.protest.passive_tfs_cohort.lis)

med.protest.passive_tfs_cohort.mis <- mediate(model.m = med.protest.mis.passive_tfs_cohort.DV, model.y = med.protest.mis.passive_tfs_cohort.stand, treat = "medtreat", 
                                              mediator = "passive_tfs_cohort", sims = 500 )
summary(med.protest.passive_tfs_cohort.mis)

med.protest.passive_tfs_cohort.his <- mediate(model.m = med.protest.his.passive_tfs_cohort.DV, model.y = med.protest.his.passive_tfs_cohort.stand, treat = "medtreat", 
                                              mediator = "passive_tfs_cohort", sims = 500 )
summary(med.protest.passive_tfs_cohort.his)



# FIX BELOW

###########################
# Psychological Mechanism #
###########################

###########################
# Cohort Emotional Health #
###########################

# CSS Measure

# Only include observations where mediator is observed

csscohort2 <- csscohort[is.na(csscohort$emohealth_css_cohort) == F,]

# Create datasets 

data.lis <- csscohort2[csscohort2$parinc == "Low-Income",]
data.mis <- csscohort2[csscohort2$parinc == "Middle-Income",]
data.his <- csscohort2[csscohort2$parinc == "High-Income",]

##########
# Voting #
##########

## Mediator Models, regressing mediator on school affluence and controls

med.voteprez2.lis.emohealth_css_cohort.DV  <- lmer(emohealth_css_cohort ~ medtreat + polaffairs_tfs + 
                                                     hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                                                     evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                     humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                                     hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                                                     notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                                                     businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                                                     south + factor(YEAR) + (1 | ACERECODE), data = data.lis[!is.na(data.lis$voteprez2),])

med.voteprez2.mis.emohealth_css_cohort.DV  <- lmer(emohealth_css_cohort ~ medtreat + polaffairs_tfs + 
                                                     hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                                                     evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                     humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                                     hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                                                     notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                                                     businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                                                     south + factor(YEAR) + (1 | ACERECODE), data = data.mis[!is.na(data.mis$voteprez2),])

med.voteprez2.his.emohealth_css_cohort.DV  <- lmer(emohealth_css_cohort ~ medtreat + polaffairs_tfs + 
                                                     hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                                                     evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                     humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                                     hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                                                     notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                                                     businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                                                     south + factor(YEAR) + (1 | ACERECODE), data = data.his[!is.na(data.his$voteprez2),])

## Outcome Models, regressing outcome on mediator, school affluence, and controls

med.voteprez2.lis.emohealth_css_cohort.stand  <- glmer(voteprez2 ~ polaffairs_tfs + emohealth_css_cohort + medtreat +
                                                         polaffairs_tfs +  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                                                         catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                         humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                                                         hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                                                         age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                                                         makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                                                         (1 | ACERECODE), family = binomial("logit"),control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                                                       data = data.lis)


med.voteprez2.mis.emohealth_css_cohort.stand  <- glmer(voteprez2 ~ polaffairs_tfs + emohealth_css_cohort + medtreat +
                                                         polaffairs_tfs +  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                                                         catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                         humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                                                         hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                                                         age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                                                         makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                                                         (1 | ACERECODE), family = binomial("logit"),control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                                                       data = data.mis)

med.voteprez2.his.emohealth_css_cohort.stand  <- glmer(voteprez2 ~ polaffairs_tfs + emohealth_css_cohort + medtreat +
                                                         polaffairs_tfs +  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                                                         catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                         humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                                                         hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                                                         age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                                                         makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                                                         (1 | ACERECODE), family = binomial("logit"),control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                                                       data = data.his)

## Run Mediation summary (exact numbers may vary due to simulations)
med.voteprez2.emohealth_css_cohort.lis <- mediate(model.m = med.voteprez2.lis.emohealth_css_cohort.DV, model.y = med.voteprez2.lis.emohealth_css_cohort.stand, treat = "medtreat", 
                                                  mediator = "emohealth_css_cohort", sims = 500 )
summary(med.voteprez2.emohealth_css_cohort.lis)

med.voteprez2.emohealth_css_cohort.mis <- mediate(model.m = med.voteprez2.mis.emohealth_css_cohort.DV, model.y = med.voteprez2.mis.emohealth_css_cohort.stand, treat = "medtreat", 
                                                  mediator = "emohealth_css_cohort", sims = 500 )
summary(med.voteprez2.emohealth_css_cohort.mis)

med.voteprez2.emohealth_css_cohort.his <- mediate(model.m = med.voteprez2.his.emohealth_css_cohort.DV, model.y = med.voteprez2.his.emohealth_css_cohort.stand, treat = "medtreat", 
                                                  mediator = "emohealth_css_cohort", sims = 500 )
summary(med.voteprez2.emohealth_css_cohort.his)

##########
# Voting #
##########

## Mediator Models, regressing mediator on school affluence and controls

med.voteprez2.lis.emohealth_chg_cohort.DV  <- lmer(emohealth_chg_cohort ~ medtreat + polaffairs_tfs + 
                                                     hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                                                     evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                     humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                                     hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                                                     notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                                                     businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                                                     south + factor(YEAR) + (1 | ACERECODE), data = data.lis[!is.na(data.lis$voteprez2),])

med.voteprez2.mis.emohealth_chg_cohort.DV  <- lmer(emohealth_chg_cohort ~ medtreat + polaffairs_tfs + 
                                                     hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                                                     evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                     humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                                     hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                                                     notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                                                     businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                                                     south + factor(YEAR) + (1 | ACERECODE), data = data.mis[!is.na(data.mis$voteprez2),])

med.voteprez2.his.emohealth_chg_cohort.DV  <- lmer(emohealth_chg_cohort ~ medtreat + polaffairs_tfs + 
                                                     hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                                                     evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                     humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                                     hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                                                     notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                                                     businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                                                     south + factor(YEAR) + (1 | ACERECODE), data = data.his[!is.na(data.his$voteprez2),])

## Outcome Models, regressing outcome on mediator, school affluence, and controls

med.voteprez2.lis.emohealth_chg_cohort.stand  <- glmer(voteprez2 ~ polaffairs_tfs + emohealth_chg_cohort + medtreat +
                                                         polaffairs_tfs +  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                                                         catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                         humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                                                         hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                                                         age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                                                         makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                                                         (1 | ACERECODE), family = binomial("logit"),control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                                                       data = data.lis)


med.voteprez2.mis.emohealth_chg_cohort.stand  <- glmer(voteprez2 ~ polaffairs_tfs + emohealth_chg_cohort + medtreat +
                                                         polaffairs_tfs +  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                                                         catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                         humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                                                         hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                                                         age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                                                         makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                                                         (1 | ACERECODE), family = binomial("logit"),control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                                                       data = data.mis)

med.voteprez2.his.emohealth_chg_cohort.stand  <- glmer(voteprez2 ~ polaffairs_tfs + emohealth_chg_cohort + medtreat +
                                                         polaffairs_tfs +  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                                                         catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                         humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                                                         hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                                                         age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                                                         makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                                                         (1 | ACERECODE), family = binomial("logit"),control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                                                       data = data.his)

## Run Mediation summary (exact numbers may vary due to simulations)
med.voteprez2.emohealth_chg_cohort.lis <- mediate(model.m = med.voteprez2.lis.emohealth_chg_cohort.DV, model.y = med.voteprez2.lis.emohealth_chg_cohort.stand, treat = "medtreat", 
                                                  mediator = "emohealth_chg_cohort", sims = 500 )
summary(med.voteprez2.emohealth_chg_cohort.lis)

med.voteprez2.emohealth_chg_cohort.mis <- mediate(model.m = med.voteprez2.mis.emohealth_chg_cohort.DV, model.y = med.voteprez2.mis.emohealth_chg_cohort.stand, treat = "medtreat", 
                                                  mediator = "emohealth_chg_cohort", sims = 500 )
summary(med.voteprez2.emohealth_chg_cohort.mis)

med.voteprez2.emohealth_chg_cohort.his <- mediate(model.m = med.voteprez2.his.emohealth_chg_cohort.DV, model.y = med.voteprez2.his.emohealth_chg_cohort.stand, treat = "medtreat", 
                                                  mediator = "emohealth_chg_cohort", sims = 500 )
summary(med.voteprez2.emohealth_chg_cohort.his)

######################
# Motivation to Lead #
######################

# CSS Measure

# Only include observations where mediator is observed

csscohort2 <- csscohort[is.na(csscohort$motivationlead_css_cohort) == F,]

# Create datasets 

data.lis <- csscohort2[csscohort2$parinc == "Low-Income",]
data.mis <- csscohort2[csscohort2$parinc == "Middle-Income",]
data.his <- csscohort2[csscohort2$parinc == "High-Income",]

##########
# Voting #
##########

## Mediator Models, regressing mediator on school affluence and controls

med.voteprez2.lis.motivationlead_css_cohort.DV  <- lmer(motivationlead_css_cohort ~ medtreat + polaffairs_tfs + 
                                                          hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                                                          evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                          humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                                          hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                                                          notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                                                          businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                                                          south + factor(YEAR) + (1 | ACERECODE), data = data.lis[!is.na(data.lis$voteprez2),])

med.voteprez2.mis.motivationlead_css_cohort.DV  <- lmer(motivationlead_css_cohort ~ medtreat + polaffairs_tfs + 
                                                          hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                                                          evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                          humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                                          hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                                                          notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                                                          businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                                                          south + factor(YEAR) + (1 | ACERECODE), data = data.mis[!is.na(data.mis$voteprez2),])

med.voteprez2.his.motivationlead_css_cohort.DV  <- lmer(motivationlead_css_cohort ~ medtreat + polaffairs_tfs + 
                                                          hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                                                          evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                          humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                                          hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                                                          notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                                                          businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                                                          south + factor(YEAR) + (1 | ACERECODE), data = data.his[!is.na(data.his$voteprez2),])

## Outcome Models, regressing outcome on mediator, school affluence, and controls

med.voteprez2.lis.motivationlead_css_cohort.stand  <- glmer(voteprez2 ~ polaffairs_tfs + motivationlead_css_cohort + medtreat +
                                                              polaffairs_tfs +  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                                                              catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                              humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                                                              hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                                                              age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                                                              makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                                                              (1 | ACERECODE), family = binomial("logit"),control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                                                            data = data.lis)


med.voteprez2.mis.motivationlead_css_cohort.stand  <- glmer(voteprez2 ~ polaffairs_tfs + motivationlead_css_cohort + medtreat +
                                                              polaffairs_tfs +  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                                                              catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                              humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                                                              hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                                                              age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                                                              makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                                                              (1 | ACERECODE), family = binomial("logit"),control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                                                            data = data.mis)

med.voteprez2.his.motivationlead_css_cohort.stand  <- glmer(voteprez2 ~ polaffairs_tfs + motivationlead_css_cohort + medtreat +
                                                              polaffairs_tfs +  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                                                              catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                              humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                                                              hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                                                              age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                                                              makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                                                              (1 | ACERECODE), family = binomial("logit"),control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                                                            data = data.his)

## Run Mediation summary (exact numbers may vary due to simulations)
med.voteprez2.motivationlead_css_cohort.lis <- mediate(model.m = med.voteprez2.lis.motivationlead_css_cohort.DV, model.y = med.voteprez2.lis.motivationlead_css_cohort.stand, treat = "medtreat", 
                                                       mediator = "motivationlead_css_cohort", sims = 500 )
summary(med.voteprez2.motivationlead_css_cohort.lis)

med.voteprez2.motivationlead_css_cohort.mis <- mediate(model.m = med.voteprez2.mis.motivationlead_css_cohort.DV, model.y = med.voteprez2.mis.motivationlead_css_cohort.stand, treat = "medtreat", 
                                                       mediator = "motivationlead_css_cohort", sims = 500 )
summary(med.voteprez2.motivationlead_css_cohort.mis)

med.voteprez2.motivationlead_css_cohort.his <- mediate(model.m = med.voteprez2.his.motivationlead_css_cohort.DV, model.y = med.voteprez2.his.motivationlead_css_cohort.stand, treat = "medtreat", 
                                                       mediator = "motivationlead_css_cohort", sims = 500 )
summary(med.voteprez2.motivationlead_css_cohort.his)

# TFS-CSS Measure

# Only include observations where mediator is observed

csscohort2 <- csscohort[is.na(csscohort$motivationlead_chg_cohort) == F,]

# Create datasets 

data.lis <- csscohort2[csscohort2$parinc == "Low-Income",]
data.mis <- csscohort2[csscohort2$parinc == "Middle-Income",]
data.his <- csscohort2[csscohort2$parinc == "High-Income",]

##########
# Voting #
##########

## Mediator Models, regressing mediator on school affluence and controls

med.voteprez2.lis.motivationlead_chg_cohort.DV  <- lmer(motivationlead_chg_cohort ~ medtreat + polaffairs_tfs + 
                                                          hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                                                          evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                          humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                                          hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                                                          notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                                                          businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                                                          south + factor(YEAR) + (1 | ACERECODE), data = data.lis[!is.na(data.lis$voteprez2),])

med.voteprez2.mis.motivationlead_chg_cohort.DV  <- lmer(motivationlead_chg_cohort ~ medtreat + polaffairs_tfs + 
                                                          hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                                                          evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                          humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                                          hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                                                          notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                                                          businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                                                          south + factor(YEAR) + (1 | ACERECODE), data = data.mis[!is.na(data.mis$voteprez2),])

med.voteprez2.his.motivationlead_chg_cohort.DV  <- lmer(motivationlead_chg_cohort ~ medtreat + polaffairs_tfs + 
                                                          hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                                                          evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                          humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                                          hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                                                          notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                                                          businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                                                          south + factor(YEAR) + (1 | ACERECODE), data = data.his[!is.na(data.his$voteprez2),])

## Outcome Models, regressing outcome on mediator, school affluence, and controls

med.voteprez2.lis.motivationlead_chg_cohort.stand  <- glmer(voteprez2 ~ polaffairs_tfs + motivationlead_chg_cohort + medtreat +
                                                              polaffairs_tfs +  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                                                              catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                              humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                                                              hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                                                              age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                                                              makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                                                              (1 | ACERECODE), family = binomial("logit"),control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                                                            data = data.lis)


med.voteprez2.mis.motivationlead_chg_cohort.stand  <- glmer(voteprez2 ~ polaffairs_tfs + motivationlead_chg_cohort + medtreat +
                                                              polaffairs_tfs +  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                                                              catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                              humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                                                              hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                                                              age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                                                              makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                                                              (1 | ACERECODE), family = binomial("logit"),control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                                                            data = data.mis)

med.voteprez2.his.motivationlead_chg_cohort.stand  <- glmer(voteprez2 ~ polaffairs_tfs + motivationlead_chg_cohort + medtreat +
                                                              polaffairs_tfs +  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                                                              catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                              humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                                                              hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                                                              age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                                                              makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                                                              (1 | ACERECODE), family = binomial("logit"),control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                                                            data = data.his)

## Run Mediation summary (exact numbers may vary due to simulations)
med.voteprez2.motivationlead_chg_cohort.lis <- mediate(model.m = med.voteprez2.lis.motivationlead_chg_cohort.DV, model.y = med.voteprez2.lis.motivationlead_chg_cohort.stand, treat = "medtreat", 
                                                       mediator = "motivationlead_chg_cohort", sims = 500 )
summary(med.voteprez2.motivationlead_chg_cohort.lis)

med.voteprez2.motivationlead_chg_cohort.mis <- mediate(model.m = med.voteprez2.mis.motivationlead_chg_cohort.DV, model.y = med.voteprez2.mis.motivationlead_chg_cohort.stand, treat = "medtreat", 
                                                       mediator = "motivationlead_chg_cohort", sims = 500 )
summary(med.voteprez2.motivationlead_chg_cohort.mis)

med.voteprez2.motivationlead_chg_cohort.his <- mediate(model.m = med.voteprez2.his.motivationlead_chg_cohort.DV, model.y = med.voteprez2.his.motivationlead_chg_cohort.stand, treat = "medtreat", 
                                                       mediator = "motivationlead_chg_cohort", sims = 500 )
summary(med.voteprez2.motivationlead_chg_cohort.his)

######################
# Academic Mechanism #
######################

#######################
# Academic Competence #
#######################

# CSS Measure

# Only include observations where mediator is observed

csscohort2 <- csscohort[is.na(csscohort$academcomp_css_cohort) == F,]

# Create datasets 

data.lis <- csscohort2[csscohort2$parinc == "Low-Income",]
data.mis <- csscohort2[csscohort2$parinc == "Middle-Income",]
data.his <- csscohort2[csscohort2$parinc == "High-Income",]

##########
# Voting #
##########

## Mediator Models, regressing mediator on school affluence and controls

med.voteprez2.lis.academcomp_css_cohort.DV  <- lmer(academcomp_css_cohort ~ medtreat + polaffairs_tfs + 
                                                      hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                                                      evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                      humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                                      hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                                                      notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                                                      businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                                                      south + factor(YEAR) + (1 | ACERECODE), data = data.lis[!is.na(data.lis$voteprez2),])

med.voteprez2.mis.academcomp_css_cohort.DV  <- lmer(academcomp_css_cohort ~ medtreat + polaffairs_tfs + 
                                                      hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                                                      evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                      humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                                      hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                                                      notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                                                      businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                                                      south + factor(YEAR) + (1 | ACERECODE), data = data.mis[!is.na(data.mis$voteprez2),])

med.voteprez2.his.academcomp_css_cohort.DV  <- lmer(academcomp_css_cohort ~ medtreat + polaffairs_tfs + 
                                                      hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                                                      evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                      humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                                      hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                                                      notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                                                      businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                                                      south + factor(YEAR) + (1 | ACERECODE), data = data.his[!is.na(data.his$voteprez2),])

## Outcome Models, regressing outcome on mediator, school affluence, and controls

med.voteprez2.lis.academcomp_css_cohort.stand  <- glmer(voteprez2 ~ polaffairs_tfs + academcomp_css_cohort + medtreat +
                                                          polaffairs_tfs +  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                                                          catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                          humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                                                          hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                                                          age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                                                          makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                                                          (1 | ACERECODE), family = binomial("logit"),control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                                                        data = data.lis)


med.voteprez2.mis.academcomp_css_cohort.stand  <- glmer(voteprez2 ~ polaffairs_tfs + academcomp_css_cohort + medtreat +
                                                          polaffairs_tfs +  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                                                          catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                          humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                                                          hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                                                          age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                                                          makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                                                          (1 | ACERECODE), family = binomial("logit"),control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                                                        data = data.mis)

med.voteprez2.his.academcomp_css_cohort.stand  <- glmer(voteprez2 ~ polaffairs_tfs + academcomp_css_cohort + medtreat +
                                                          polaffairs_tfs +  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                                                          catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                          humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                                                          hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                                                          age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                                                          makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                                                          (1 | ACERECODE), family = binomial("logit"),control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                                                        data = data.his)

## Run Mediation summary (exact numbers may vary due to simulations)
med.voteprez2.academcomp_css_cohort.lis <- mediate(model.m = med.voteprez2.lis.academcomp_css_cohort.DV, model.y = med.voteprez2.lis.academcomp_css_cohort.stand, treat = "medtreat", 
                                                   mediator = "academcomp_css_cohort", sims = 500 )
summary(med.voteprez2.academcomp_css_cohort.lis)

med.voteprez2.academcomp_css_cohort.mis <- mediate(model.m = med.voteprez2.mis.academcomp_css_cohort.DV, model.y = med.voteprez2.mis.academcomp_css_cohort.stand, treat = "medtreat", 
                                                   mediator = "academcomp_css_cohort", sims = 500 )
summary(med.voteprez2.academcomp_css_cohort.mis)

med.voteprez2.academcomp_css_cohort.his <- mediate(model.m = med.voteprez2.his.academcomp_css_cohort.DV, model.y = med.voteprez2.his.academcomp_css_cohort.stand, treat = "medtreat", 
                                                   mediator = "academcomp_css_cohort", sims = 500 )
summary(med.voteprez2.academcomp_css_cohort.his)

# TFS-CSS Measure

# Only include observations where mediator is observed

csscohort2 <- csscohort[is.na(csscohort$academcomp_chg_cohort) == F,]

# Create datasets 

data.lis <- csscohort2[csscohort2$parinc == "Low-Income",]
data.mis <- csscohort2[csscohort2$parinc == "Middle-Income",]
data.his <- csscohort2[csscohort2$parinc == "High-Income",]

##########
# Voting #
##########

## Mediator Models, regressing mediator on school affluence and controls

med.voteprez2.lis.academcomp_chg_cohort.DV  <- lmer(academcomp_chg_cohort ~ medtreat + polaffairs_tfs + 
                                                      hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                                                      evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                      humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                                      hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                                                      notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                                                      businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                                                      south + factor(YEAR) + (1 | ACERECODE), data = data.lis[!is.na(data.lis$voteprez2),])

med.voteprez2.mis.academcomp_chg_cohort.DV  <- lmer(academcomp_chg_cohort ~ medtreat + polaffairs_tfs + 
                                                      hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                                                      evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                      humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                                      hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                                                      notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                                                      businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                                                      south + factor(YEAR) + (1 | ACERECODE), data = data.mis[!is.na(data.mis$voteprez2),])

med.voteprez2.his.academcomp_chg_cohort.DV  <- lmer(academcomp_chg_cohort ~ medtreat + polaffairs_tfs + 
                                                      hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                                                      evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                      humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                                      hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                                                      notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                                                      businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                                                      south + factor(YEAR) + (1 | ACERECODE), data = data.his[!is.na(data.his$voteprez2),])

## Outcome Models, regressing outcome on mediator, school affluence, and controls

med.voteprez2.lis.academcomp_chg_cohort.stand  <- glmer(voteprez2 ~ polaffairs_tfs + academcomp_chg_cohort + medtreat +
                                                          polaffairs_tfs +  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                                                          catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                          humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                                                          hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                                                          age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                                                          makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                                                          (1 | ACERECODE), family = binomial("logit"),control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                                                        data = data.lis)


med.voteprez2.mis.academcomp_chg_cohort.stand  <- glmer(voteprez2 ~ polaffairs_tfs + academcomp_chg_cohort + medtreat +
                                                          polaffairs_tfs +  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                                                          catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                          humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                                                          hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                                                          age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                                                          makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                                                          (1 | ACERECODE), family = binomial("logit"),control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                                                        data = data.mis)

med.voteprez2.his.academcomp_chg_cohort.stand  <- glmer(voteprez2 ~ polaffairs_tfs + academcomp_chg_cohort + medtreat +
                                                          polaffairs_tfs +  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                                                          catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                          humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                                                          hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                                                          age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                                                          makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                                                          (1 | ACERECODE), family = binomial("logit"),control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                                                        data = data.his)

## Run Mediation summary (exact numbers may vary due to simulations)
med.voteprez2.academcomp_chg_cohort.lis <- mediate(model.m = med.voteprez2.lis.academcomp_chg_cohort.DV, model.y = med.voteprez2.lis.academcomp_chg_cohort.stand, treat = "medtreat", 
                                                   mediator = "academcomp_chg_cohort", sims = 500 )
summary(med.voteprez2.academcomp_chg_cohort.lis)

med.voteprez2.academcomp_chg_cohort.mis <- mediate(model.m = med.voteprez2.mis.academcomp_chg_cohort.DV, model.y = med.voteprez2.mis.academcomp_chg_cohort.stand, treat = "medtreat", 
                                                   mediator = "academcomp_chg_cohort", sims = 500 )
summary(med.voteprez2.academcomp_chg_cohort.mis)

med.voteprez2.academcomp_chg_cohort.his <- mediate(model.m = med.voteprez2.his.academcomp_chg_cohort.DV, model.y = med.voteprez2.his.academcomp_chg_cohort.stand, treat = "medtreat", 
                                                   mediator = "academcomp_chg_cohort", sims = 500 )
summary(med.voteprez2.academcomp_chg_cohort.his)

####################
# Social Mechanism #
####################

##########################
# Social Self-Confidence #
##########################

# CSS Measure

# Only include observations where mediator is observed

csscohort2 <- csscohort[is.na(csscohort$soccon_css_cohort) == F,]

# Create datasets 

data.lis <- csscohort2[csscohort2$parinc == "Low-Income",]
data.mis <- csscohort2[csscohort2$parinc == "Middle-Income",]
data.his <- csscohort2[csscohort2$parinc == "High-Income",]

##########
# Voting #
##########

## Mediator Models, regressing mediator on school affluence and controls

med.voteprez2.lis.soccon_css_cohort.DV  <- lmer(soccon_css_cohort ~ medtreat + polaffairs_tfs + 
                                                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                                                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                                                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                                                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                                                  south + factor(YEAR) + (1 | ACERECODE), data = data.lis[!is.na(data.lis$voteprez2),])

med.voteprez2.mis.soccon_css_cohort.DV  <- lmer(soccon_css_cohort ~ medtreat + polaffairs_tfs + 
                                                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                                                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                                                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                                                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                                                  south + factor(YEAR) + (1 | ACERECODE), data = data.mis[!is.na(data.mis$voteprez2),])

med.voteprez2.his.soccon_css_cohort.DV  <- lmer(soccon_css_cohort ~ medtreat + polaffairs_tfs + 
                                                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                                                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                                                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                                                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                                                  south + factor(YEAR) + (1 | ACERECODE), data = data.his[!is.na(data.his$voteprez2),])

## Outcome Models, regressing outcome on mediator, school affluence, and controls

med.voteprez2.lis.soccon_css_cohort.stand  <- glmer(voteprez2 ~ polaffairs_tfs + soccon_css_cohort + medtreat +
                                                      polaffairs_tfs +  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                                                      catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                      humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                                                      hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                                                      age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                                                      makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                                                      (1 | ACERECODE), family = binomial("logit"),control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                                                    data = data.lis)


med.voteprez2.mis.soccon_css_cohort.stand  <- glmer(voteprez2 ~ polaffairs_tfs + soccon_css_cohort + medtreat +
                                                      polaffairs_tfs +  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                                                      catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                      humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                                                      hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                                                      age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                                                      makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                                                      (1 | ACERECODE), family = binomial("logit"),control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                                                    data = data.mis)

med.voteprez2.his.soccon_css_cohort.stand  <- glmer(voteprez2 ~ polaffairs_tfs + soccon_css_cohort + medtreat +
                                                      polaffairs_tfs +  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                                                      catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                      humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                                                      hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                                                      age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                                                      makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                                                      (1 | ACERECODE), family = binomial("logit"),control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                                                    data = data.his)

## Run Mediation summary (exact numbers may vary due to simulations)
med.voteprez2.soccon_css_cohort.lis <- mediate(model.m = med.voteprez2.lis.soccon_css_cohort.DV, model.y = med.voteprez2.lis.soccon_css_cohort.stand, treat = "medtreat", 
                                               mediator = "soccon_css_cohort", sims = 500 )
summary(med.voteprez2.soccon_css_cohort.lis)

med.voteprez2.soccon_css_cohort.mis <- mediate(model.m = med.voteprez2.mis.soccon_css_cohort.DV, model.y = med.voteprez2.mis.soccon_css_cohort.stand, treat = "medtreat", 
                                               mediator = "soccon_css_cohort", sims = 500 )
summary(med.voteprez2.soccon_css_cohort.mis)

med.voteprez2.soccon_css_cohort.his <- mediate(model.m = med.voteprez2.his.soccon_css_cohort.DV, model.y = med.voteprez2.his.soccon_css_cohort.stand, treat = "medtreat", 
                                               mediator = "soccon_css_cohort", sims = 500 )
summary(med.voteprez2.soccon_css_cohort.his)

# TFS-CSS Measure

# Only include observations where mediator is observed

csscohort2 <- csscohort[is.na(csscohort$soccon_chg_cohort) == F,]

# Create datasets 

data.lis <- csscohort2[csscohort2$parinc == "Low-Income",]
data.mis <- csscohort2[csscohort2$parinc == "Middle-Income",]
data.his <- csscohort2[csscohort2$parinc == "High-Income",]

##########
# Voting #
##########

## Mediator Models, regressing mediator on school affluence and controls

med.voteprez2.lis.soccon_chg_cohort.DV  <- lmer(soccon_chg_cohort ~ medtreat + polaffairs_tfs + 
                                                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                                                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                                                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                                                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                                                  south + factor(YEAR) + (1 | ACERECODE), data = data.lis[!is.na(data.lis$voteprez2),])

med.voteprez2.mis.soccon_chg_cohort.DV  <- lmer(soccon_chg_cohort ~ medtreat + polaffairs_tfs + 
                                                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                                                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                                                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                                                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                                                  south + factor(YEAR) + (1 | ACERECODE), data = data.mis[!is.na(data.mis$voteprez2),])

med.voteprez2.his.soccon_chg_cohort.DV  <- lmer(soccon_chg_cohort ~ medtreat + polaffairs_tfs + 
                                                  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                                                  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                  humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                                  hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                                                  notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                                                  businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                                                  south + factor(YEAR) + (1 | ACERECODE), data = data.his[!is.na(data.his$voteprez2),])

## Outcome Models, regressing outcome on mediator, school affluence, and controls

med.voteprez2.lis.soccon_chg_cohort.stand  <- glmer(voteprez2 ~ polaffairs_tfs + soccon_chg_cohort + medtreat +
                                                      polaffairs_tfs +  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                                                      catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                      humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                                                      hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                                                      age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                                                      makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                                                      (1 | ACERECODE), family = binomial("logit"),control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                                                    data = data.lis)


med.voteprez2.mis.soccon_chg_cohort.stand  <- glmer(voteprez2 ~ polaffairs_tfs + soccon_chg_cohort + medtreat +
                                                      polaffairs_tfs +  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                                                      catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                      humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                                                      hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                                                      age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                                                      makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                                                      (1 | ACERECODE), family = binomial("logit"),control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                                                    data = data.mis)

med.voteprez2.his.soccon_chg_cohort.stand  <- glmer(voteprez2 ~ polaffairs_tfs + soccon_chg_cohort + medtreat +
                                                      polaffairs_tfs +  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                                                      catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                      humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                                                      hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                                                      age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                                                      makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                                                      (1 | ACERECODE), family = binomial("logit"),control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                                                    data = data.his)

## Run Mediation summary (exact numbers may vary due to simulations)
med.voteprez2.soccon_chg_cohort.lis <- mediate(model.m = med.voteprez2.lis.soccon_chg_cohort.DV, model.y = med.voteprez2.lis.soccon_chg_cohort.stand, treat = "medtreat", 
                                               mediator = "soccon_chg_cohort", sims = 500 )
summary(med.voteprez2.soccon_chg_cohort.lis)

med.voteprez2.soccon_chg_cohort.mis <- mediate(model.m = med.voteprez2.mis.soccon_chg_cohort.DV, model.y = med.voteprez2.mis.soccon_chg_cohort.stand, treat = "medtreat", 
                                               mediator = "soccon_chg_cohort", sims = 500 )
summary(med.voteprez2.soccon_chg_cohort.mis)

med.voteprez2.soccon_chg_cohort.his <- mediate(model.m = med.voteprez2.his.soccon_chg_cohort.DV, model.y = med.voteprez2.his.soccon_chg_cohort.stand, treat = "medtreat", 
                                               mediator = "soccon_chg_cohort", sims = 500 )
summary(med.voteprez2.soccon_chg_cohort.his)




######################
# CSS Political Norm #
######################

# CSS Measure

# Only include observations where mediator is observed

csscohort2 <- csscohort[is.na(csscohort$passive_index_css_avg_cohort) == F,]

# Create datasets 

data.lis <- csscohort2[csscohort2$parinc == "Low-Income",]
data.mis <- csscohort2[csscohort2$parinc == "Middle-Income",]
data.his <- csscohort2[csscohort2$parinc == "High-Income",]



##########
# Voting #
##########

## Mediator Models, regressing mediator on school affluence and controls

med.voteprez2.lis.passive_index_css_avg_cohort.DV  <- lmer(passive_index_css_avg_cohort ~ medtreat + polaffairs_tfs + 
                                                             hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                                                             evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                             humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                                             hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                                                             notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                                                             businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                                                             south + factor(YEAR) + (1 | ACERECODE), data = data.lis[!is.na(data.lis$voteprez2),])

med.voteprez2.mis.passive_index_css_avg_cohort.DV  <- lmer(passive_index_css_avg_cohort ~ medtreat + polaffairs_tfs + 
                                                             hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                                                             evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                             humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                                             hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                                                             notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                                                             businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                                                             south + factor(YEAR) + (1 | ACERECODE), data = data.mis[!is.na(data.mis$voteprez2),])

med.voteprez2.his.passive_index_css_avg_cohort.DV  <- lmer(passive_index_css_avg_cohort ~ medtreat + polaffairs_tfs + 
                                                             hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                                                             evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                             humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                                             hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                                                             notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                                                             businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                                                             south + factor(YEAR) + (1 | ACERECODE), data = data.his[!is.na(data.his$voteprez2),])

## Outcome Models, regressing outcome on mediator, school affluence, and controls

med.voteprez2.lis.passive_index_css_avg_cohort.stand  <- glmer(voteprez2 ~ polaffairs_tfs + passive_index_css_avg_cohort + medtreat +
                                                                 polaffairs_tfs +  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                                                                 catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                                 humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                                                                 hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                                                                 age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                                                                 makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                                                                 (1 | ACERECODE), family = binomial("logit"),control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                                                               data = data.lis)


med.voteprez2.mis.passive_index_css_avg_cohort.stand  <- glmer(voteprez2 ~ polaffairs_tfs + passive_index_css_avg_cohort + medtreat +
                                                                 polaffairs_tfs +  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                                                                 catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                                 humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                                                                 hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                                                                 age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                                                                 makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                                                                 (1 | ACERECODE), family = binomial("logit"),control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                                                               data = data.mis)

med.voteprez2.his.passive_index_css_avg_cohort.stand  <- glmer(voteprez2 ~ polaffairs_tfs + passive_index_css_avg_cohort + medtreat +
                                                                 polaffairs_tfs +  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                                                                 catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                                 humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                                                                 hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                                                                 age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                                                                 makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                                                                 (1 | ACERECODE), family = binomial("logit"),control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                                                               data = data.his)

## Run Mediation summary (exact numbers may vary due to simulations)
med.voteprez2.passive_index_css_avg_cohort.lis <- mediate(model.m = med.voteprez2.lis.passive_index_css_avg_cohort.DV, model.y = med.voteprez2.lis.passive_index_css_avg_cohort.stand, treat = "medtreat", 
                                                          mediator = "passive_index_css_avg_cohort", sims = 500 )
summary(med.voteprez2.passive_index_css_avg_cohort.lis)

med.voteprez2.passive_index_css_avg_cohort.mis <- mediate(model.m = med.voteprez2.mis.passive_index_css_avg_cohort.DV, model.y = med.voteprez2.mis.passive_index_css_avg_cohort.stand, treat = "medtreat", 
                                                          mediator = "passive_index_css_avg_cohort", sims = 500 )
summary(med.voteprez2.passive_index_css_avg_cohort.mis)

med.voteprez2.passive_index_css_avg_cohort.his <- mediate(model.m = med.voteprez2.his.passive_index_css_avg_cohort.DV, model.y = med.voteprez2.his.passive_index_css_avg_cohort.stand, treat = "medtreat", 
                                                          mediator = "passive_index_css_avg_cohort", sims = 500 )
summary(med.voteprez2.passive_index_css_avg_cohort.his)


# TFS-CSS Measure

# Only include observations where mediator is observed

csscohort2 <- csscohort[is.na(csscohort$passive_index_chg_avg_cohort) == F,]

# Create datasets 

data.lis <- csscohort2[csscohort2$parinc == "Low-Income",]
data.mis <- csscohort2[csscohort2$parinc == "Middle-Income",]
data.his <- csscohort2[csscohort2$parinc == "High-Income",]

##########
# Voting #
##########

## Mediator Models, regressing mediator on school affluence and controls

med.voteprez2.lis.passive_index_chg_avg_cohort.DV  <- lmer(passive_index_chg_avg_cohort ~ medtreat + polaffairs_tfs + 
                                                             hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                                                             evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                             humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                                             hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                                                             notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                                                             businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                                                             south + factor(YEAR) + (1 | ACERECODE), data = data.lis[!is.na(data.lis$voteprez2),])

med.voteprez2.mis.passive_index_chg_avg_cohort.DV  <- lmer(passive_index_chg_avg_cohort ~ medtreat + polaffairs_tfs + 
                                                             hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                                                             evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                             humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                                             hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                                                             notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                                                             businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                                                             south + factor(YEAR) + (1 | ACERECODE), data = data.mis[!is.na(data.mis$voteprez2),])

med.voteprez2.his.passive_index_chg_avg_cohort.DV  <- lmer(passive_index_chg_avg_cohort ~ medtreat + polaffairs_tfs + 
                                                             hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + catholic + 
                                                             evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                             humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper +
                                                             hihispanicper + hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper + 
                                                             notenglishfirstper + age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + 
                                                             businesstfsper + makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast +  
                                                             south + factor(YEAR) + (1 | ACERECODE), data = data.his[!is.na(data.his$voteprez2),])

## Outcome Models, regressing outcome on mediator, school affluence, and controls

med.voteprez2.lis.passive_index_chg_avg_cohort.stand  <- glmer(voteprez2 ~ polaffairs_tfs + passive_index_chg_avg_cohort + medtreat +
                                                                 polaffairs_tfs +  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                                                                 catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                                 humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                                                                 hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                                                                 age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                                                                 makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                                                                 (1 | ACERECODE), family = binomial("logit"),control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                                                               data = data.lis)


med.voteprez2.mis.passive_index_chg_avg_cohort.stand  <- glmer(voteprez2 ~ polaffairs_tfs + passive_index_chg_avg_cohort + medtreat +
                                                                 polaffairs_tfs +  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                                                                 catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                                 humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                                                                 hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                                                                 age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                                                                 makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                                                                 (1 | ACERECODE), family = binomial("logit"),control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                                                               data = data.mis)

med.voteprez2.his.passive_index_chg_avg_cohort.stand  <- glmer(voteprez2 ~ polaffairs_tfs + passive_index_chg_avg_cohort + medtreat +
                                                                 polaffairs_tfs +  hitestscore + testscore_na + female + asian + hispanic + black + othrace + jewish + 
                                                                 catholic +  evangelical + otherornorelig + notenglishfirst + age17orless + age19 + age20 + socscitfs + 
                                                                 humantfs + sciencetfs +  businesstfs + makemoneyvimp + hitestscoreper + hiasianper + hihispanicper + 
                                                                 hiothraceper + hijewishper + hicatholicper + hievangelicalper + hiotherornoreligper +  notenglishfirstper + 
                                                                 age17orlessper + age19per + age20per + socscitfsper + humantfsper +  sciencetfsper + businesstfsper + 
                                                                 makemoneyvimpper + mostlyfemale + mostlyblack +  largesb + public + college + neast + south + factor(YEAR) + 
                                                                 (1 | ACERECODE), family = binomial("logit"),control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE),
                                                               data = data.his)

## Run Mediation summary (exact numbers may vary due to simulations)
med.voteprez2.passive_index_chg_avg_cohort.lis <- mediate(model.m = med.voteprez2.lis.passive_index_chg_avg_cohort.DV, model.y = med.voteprez2.lis.passive_index_chg_avg_cohort.stand, treat = "medtreat", 
                                                          mediator = "passive_index_chg_avg_cohort", sims = 500 )
summary(med.voteprez2.passive_index_chg_avg_cohort.lis)

med.voteprez2.passive_index_chg_avg_cohort.mis <- mediate(model.m = med.voteprez2.mis.passive_index_chg_avg_cohort.DV, model.y = med.voteprez2.mis.passive_index_chg_avg_cohort.stand, treat = "medtreat", 
                                                          mediator = "passive_index_chg_avg_cohort", sims = 500 )
summary(med.voteprez2.passive_index_chg_avg_cohort.mis)

med.voteprez2.passive_index_chg_avg_cohort.his <- mediate(model.m = med.voteprez2.his.passive_index_chg_avg_cohort.DV, model.y = med.voteprez2.his.passive_index_chg_avg_cohort.stand, treat = "medtreat", 
                                                          mediator = "passive_index_chg_avg_cohort", sims = 500 )
summary(med.voteprez2.passive_index_chg_avg_cohort.his)

